日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

每个Power BI开发人员的Power Query提示

發(fā)布時(shí)間:2023/11/29 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 每个Power BI开发人员的Power Query提示 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

If someone asks you to define the Power Query, what should you say? If you’ve ever worked with Power BI, there is no chance that you haven’t used Power Query, even if you weren’t aware of it. Therefore, one could easily say that Power Query is the “heart and soul” of Power BI…

如果有人要求您定義超級(jí)查詢,您應(yīng)該怎么說(shuō)? 如果您曾經(jīng)使用過(guò)Power BI,那么即使您不了解Power Query,也絕不會(huì)使用它。 因此,可以輕松地說(shuō)Power Query是Power BI的“靈魂”

In more official wording, Power Query is Microsoft’s technology for connecting and transforming data from multiple sources. As Microsoft’s official documentation states, you can connect to hundreds of different data sources and perform more than 300 transformations on your data.

用更正式的措辭來(lái)說(shuō),Power Query是Microsoft的技術(shù),用于連接和轉(zhuǎn)換來(lái)自多個(gè)源的數(shù)據(jù)。 如Microsoft的官方文檔所述,您可以連接到數(shù)百個(gè)不同的數(shù)據(jù)源,并對(duì)數(shù)據(jù)執(zhí)行300多次轉(zhuǎn)換。

The key advantage of Power Query is that you can perform complex data transformations with little or no coding skills! Additionally, all steps you’ve applied during the data transformation process are being saved, so every time you refresh your dataset, those steps will be automatically applied to shape your data, which is a real time-saver.

Power Query的主要優(yōu)勢(shì)在于,您幾乎不需要或幾乎沒(méi)有編碼技能就可以執(zhí)行復(fù)雜的數(shù)據(jù)轉(zhuǎn)換! 此外,還將保存您在數(shù)據(jù)轉(zhuǎn)換過(guò)程中應(yīng)用的所有步驟,因此,每次刷新數(shù)據(jù)集時(shí),這些步驟將自動(dòng)應(yīng)用以成形數(shù)據(jù),這是真正的節(jié)省時(shí)間。

Out of those 300+ transformations, it’s extremely hard to choose the most useful ones, but I will share my top 3 tips related to Power Query (and its powerful M language). You should also learn non Power Query related tips for boosting Power BI development.

在這300多個(gè)轉(zhuǎn)換中,很難選擇最有用的轉(zhuǎn)換,但是我將分享與Power Query(及其強(qiáng)大的M語(yǔ)言)相關(guān)的3個(gè)技巧。 您還應(yīng)該學(xué)習(xí)與Power Query不相關(guān)的技巧,以促進(jìn)Power BI的開發(fā) 。

技巧1 – Power Query Editor中的省時(shí)功能 (Tip #1 — Time Savers in Power Query Editor)

I need to say this immediately: there are tons of time-saving actions you can perform with clever usage of Power Query Editor, so I will narrow my recommendation to a few I’m using most often.

我需要立即說(shuō)出這一點(diǎn):通過(guò)巧妙地使用Power Query Editor,您可以執(zhí)行許多省時(shí)的操作,因此,我將建議范圍縮小到最常使用的幾個(gè)。

I bet that you face this scenario almost every time you are preparing data for your Power BI report. You import a wide table with a lot of columns and you need to get rid of some of them. You are scrolling from left to right, choosing which columns to keep and which to remove.

我敢打賭,幾乎每次為Power BI報(bào)告準(zhǔn)備數(shù)據(jù)時(shí),您都會(huì)遇到這種情況。 您導(dǎo)入一個(gè)包含很多列的寬表,您需要擺脫其中的一些列。 您從左到右滾動(dòng),選擇要保留的列和要?jiǎng)h除的列。

But, there is a much more sophisticated way to obtain this:

但是,有一種更復(fù)雜的方法可以實(shí)現(xiàn)此目的:

As you see in the illustration above, instead of exhausting scrolling, just open Choose Columns drop-down menu, select Choose Columns, and select columns you want to keep! Soooo handy!

如上圖所示,只需打開“選擇列”下拉菜單,選擇“選擇列”,然后選擇要保留的列即可,而不是窮盡滾動(dòng)! 太好用了!

Another tip under the same drop-down menu: choose Go To Column and you will be navigated straight to that column, so you can perform any kind of transformation you want on that specific column, again without the need to waste your time trying to find it in wide “30+ column tables”…

在同一下拉菜單下的另一個(gè)提示:選擇“轉(zhuǎn)到列”,您將直接導(dǎo)航到該列,因此您可以在該特定列上執(zhí)行所需的任何類型的轉(zhuǎn)換,而無(wú)需浪費(fèi)您的時(shí)間來(lái)查找在“ 30多個(gè)列”表中…

Another hidden gem is the “Query Dependencies” button under the View tab.

另一個(gè)隱藏的元素是“視圖”選項(xiàng)卡下的“查詢依賴項(xiàng)”按鈕。

This is extremely useful when working with complex models when data comes from multiple different sources, or not all data is being loaded to the report.

當(dāng)數(shù)據(jù)來(lái)自多個(gè)不同來(lái)源或并非所有數(shù)據(jù)都已加載到報(bào)表中時(shí),這在處理復(fù)雜模型時(shí)非常有用。

Using Query Dependencies will give you a quick visual overview of your data model:

使用查詢依賴關(guān)系將使您快速直觀地了解數(shù)據(jù)模型:

Instead of clicking on every single entity in your data model to check its status, you can have this all in one place, and even better, it’s visually represented!

您無(wú)需將數(shù)據(jù)模型中的每個(gè)實(shí)體都單擊來(lái)檢查其狀態(tài),而是可以將它們?nèi)考性谝粋€(gè)地方,甚至更好地以可視方式進(jìn)行顯示!

Imagine having data coming from CSV files, SQL Server database, and Sharepoint lists, and part of that data doesn’t even being loaded to the report for whatever reasons. This is a huuuuge time saver!

想象一下,數(shù)據(jù)來(lái)自CSV文件,SQL Server數(shù)據(jù)庫(kù)和Sharepoint列表,并且無(wú)論出于何種原因,這些數(shù)據(jù)的一部分甚至都沒(méi)有加載到報(bào)表中。 這節(jié)省了很多時(shí)間!

技巧2-使用M語(yǔ)言進(jìn)行頻繁的計(jì)算 (Tip #2 — Use M language to perform frequent calculations)

One of the most common business requests is to calculate the day difference between different events. For example, I want to know the age structure of my customers, so I need to calculate their age every time data is refreshed.

最常見的業(yè)務(wù)請(qǐng)求之一是計(jì)算不同事件之間的日差。 例如,我想知道客戶的年齡結(jié)構(gòu),因此我需要在每次刷新數(shù)據(jù)時(shí)計(jì)算他們的年齡。

Or, I need to check how many days are customers late with their payments. As you can assume, these figures need to be calculated dynamically, so here comes M language to the rescue!

或者,我需要檢查客戶延遲付款的天數(shù)。 如您所料,這些數(shù)字需要?jiǎng)討B(tài)計(jì)算,因此可以使用M語(yǔ)言進(jìn)行救援!

Let’s demonstrate on calculating customers’ age. Basically, there are two ways to achieve this in Power Query: first doesn’t need any coding, but it requires multiple steps to be applied. Therefore, I prefer the second option, when you put the whole calculation in one step!

讓我們演示一下計(jì)算客戶的年齡。 基本上,有兩種方法可以在Power Query中實(shí)現(xiàn)此目的:首先不需要任何編碼,但是需要應(yīng)用多個(gè)步驟。 因此,當(dāng)您將整個(gè)計(jì)算放在一個(gè)步驟中時(shí),我更喜歡第二種選擇!

This method visualized above requires three separate steps. First, we insert a new column and under the Date drop-down menu, we choose the Age option. However, Power Query calculates Age in days since BirthDate till today. Therefore, we need to convert this awkward number to years, which is done under the Duration drop-down menu and selecting Total Years. Again, we are getting an awkward result, because age is displayed as a decimal number with multiple decimal places (this is correct, but not intuitive). One last step is to round down that number, which is performed under Rounding.

上面可視化的此方法需要三個(gè)單獨(dú)的步驟。 首先,我們插入一個(gè)新列,然后在“日期”下拉菜單下,選擇“年齡”選項(xiàng)。 但是,Power Query會(huì)計(jì)算從出生日期到今天的天數(shù)。 因此,我們需要將此尷尬的數(shù)字轉(zhuǎn)換為年,這可以在“持續(xù)時(shí)間”下拉菜單中選擇“總年”來(lái)完成。 再次,我們得到一個(gè)尷尬的結(jié)果,因?yàn)槟挲g顯示為帶有多個(gè)小數(shù)位的十進(jìn)制數(shù)字(這是正確的,但不直觀)。 最后一步是將數(shù)字四舍五入,這在四舍五入下執(zhí)行。

Now, nothing is wrong with this approach, but if you are doing multiple calculations, your Power Query Applied Steps pane will finish polluted with many unnecessary steps.

現(xiàn)在,這種方法沒(méi)有什么問(wèn)題,但是,如果您進(jìn)行多次計(jì)算,那么“ Power Query Applied Steps”窗格將被許多??不必要的步驟污染。

That’s why I prefer another option: under the Add Column tab, choose a Custom column and enter the following formula:

這就是為什么我喜歡另一個(gè)選項(xiàng):在“添加列”選項(xiàng)卡下,選擇一個(gè)“自定義”列并輸入以下公式:

Number.RoundDown(Duration.TotalDays(Date.From(DateTime.LocalNow()) - [BirthDate])/365)

This way, we perform all iterations from the previous version in one run and we have only one step applied! Mission accomplished in a more elegant way…

這樣,我們可以一次運(yùn)行執(zhí)行先前版本的所有迭代,并且只應(yīng)用了一個(gè)步驟! 任務(wù)以更優(yōu)雅的方式完成...

提示3 –自定義靈活日期維度 (Tip #3 — Custom Flexible Date Dimension)

This one is my favorite! First, I thought to dedicate a separate post to this, but in the end, I’ve decided to put it here, since I’ve already written the whole series on proper handling of the Date dimension.

這個(gè)是我的最愛! 首先,我想為此單獨(dú)寫一篇文章,但是最后,我決定將它放在這里,因?yàn)槲乙呀?jīng)寫了整個(gè)系列有關(guān)Date維的正確處理 。

I won’t spend much time explaining the importance of having separate Date dimension (that is the topic of another article) — I will just briefly say: technically, Power BI allows you to “survive” without separate Date dimension, but don’t do it! Just don’t…

我不會(huì)花很多時(shí)間來(lái)說(shuō)明使用單獨(dú)的Date維度的重要性( 這是另一篇文章的主題 )—我只是簡(jiǎn)單地說(shuō):從技術(shù)上講,Power BI允許您在沒(méi)有單獨(dú)的Date維度的情況下“生存”,但不要做吧! 只是不要...

There are multiple solutions to create separate Date dimension in your data model, but here I will focus on using M language to achieve this.

有多種解決方案可在您的數(shù)據(jù)模型中創(chuàng)建單獨(dú)的Date維度 ,但是在這里,我將重點(diǎn)介紹使用M語(yǔ)言來(lái)實(shí)現(xiàn)這一點(diǎn)。

There are plenty of ready-made scripts on the web for creating a fully functional Date dimension, but I’ve chosen this solution from Reza Rad (by the way, on his blog you can learn a lot of useful stuff).

Web上有很多現(xiàn)成的腳本可用于創(chuàng)建功能齊全的Date維度,但是我從Reza Rad選擇了此解決方案 (順便說(shuō)一句,在他的博客上,您可以學(xué)到很多有用的東西)。

Open new Power BI file and choose Blank query under Get data:

打開新的Power BI文件,然后在“獲取數(shù)據(jù)”下選擇“空白查詢”:

This will navigate you to Power Query Editor. The next step is of key importance in order to have a highly customized Date dimension.

這會(huì)將您導(dǎo)航到Power Query Editor。 下一步對(duì)于擁有高度定制的“日期”維度至關(guān)重要。

Under Manage Parameters, select New Parameter and format it like on the following image:

在“管理參數(shù)”下,選擇“新參數(shù)”,然后將其格式化,如下圖所示:

This way, you are defining from which year you want your Date dimension to start. Do exactly the same for EndYear:

這樣,您可以定義要從哪個(gè)年份開始“日期”維度。 對(duì)EndYear執(zhí)行完全相同的操作:

Now that we have both our parameters defined, we can switch to Advanced Editor and paste the whole Reza’s script for creating specific columns of our Date dimension (of course, feel free to include/exclude more columns according to your needs).

現(xiàn)在我們已經(jīng)定義了兩個(gè)參數(shù),我們可以切換到Advanced Editor并粘貼整個(gè)Reza的腳本,以創(chuàng)建Date維度的特定列(當(dāng)然,可以根據(jù)您的需要隨意包含/排除更多列)。

And here is the whole script:

這是整個(gè)腳本:

let
StartDate = #date(StartYear,1,1),
EndDate = #date(EndYear,12,31),
NumberOfDays = Duration.Days( EndDate - StartDate ),
Dates = List.Dates(StartDate, NumberOfDays+1, #duration(1,0,0,0)),
#"Converted to Table" = Table.FromList(Dates, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "FullDateAlternateKey"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"FullDateAlternateKey", type date}}),
#"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([FullDateAlternateKey]), type number),
#"Inserted Month" = Table.AddColumn(#"Inserted Year", "Month", each Date.Month([FullDateAlternateKey]), type number),
#"Inserted Month Name" = Table.AddColumn(#"Inserted Month", "Month Name", each Date.MonthName([FullDateAlternateKey]), type text),
#"Inserted Quarter" = Table.AddColumn(#"Inserted Month Name", "Quarter", each Date.QuarterOfYear([FullDateAlternateKey]), type number),
#"Inserted Week of Year" = Table.AddColumn(#"Inserted Quarter", "Week of Year", each Date.WeekOfYear([FullDateAlternateKey]), type number),
#"Inserted Week of Month" = Table.AddColumn(#"Inserted Week of Year", "Week of Month", each Date.WeekOfMonth([FullDateAlternateKey]), type number),
#"Inserted Day" = Table.AddColumn(#"Inserted Week of Month", "Day", each Date.Day([FullDateAlternateKey]), type number),
#"Inserted Day of Week" = Table.AddColumn(#"Inserted Day", "Day of Week", each Date.DayOfWeek([FullDateAlternateKey]), type number),
#"Inserted Day of Year" = Table.AddColumn(#"Inserted Day of Week", "Day of Year", each Date.DayOfYear([FullDateAlternateKey]), type number),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Day of Year", "Day Name", each Date.DayOfWeekName([FullDateAlternateKey]), type text)
in
#"Inserted Day Name"

Hit Close & Apply and we now have fully functional Date dimension in our data model!

點(diǎn)擊“關(guān)閉并應(yīng)用”,我們現(xiàn)在在數(shù)據(jù)模型中具有完全可用的“日期”維!

We can easily change the time frame by managing parameters and switching year values.

通過(guò)管理參數(shù)和切換年份值,我們可以輕松更改時(shí)間范圍。

And now comes ice on the cake, as a bonus tip: save your file as .pbit (Power BI Template file). This way, when you starting your Power BI projects, you don’t need to create a Date dimension from Scratch, wasting your time and energy — it will already be there for you!

現(xiàn)在,錦上添花了,作為一個(gè)額外的提示:將文件另存為.pbit(Power BI Template文件)。 這樣,當(dāng)您啟動(dòng)Power BI項(xiàng)目時(shí),無(wú)需從頭開始創(chuàng)建Date維度,這會(huì)浪費(fèi)您的時(shí)間和精力—它已經(jīng)可以為您服務(wù)!

You want more? There it is. Once you open your template file, you will be prompted to enter values for Start Year and End Year, which means that you can customize the time-frame from the report to report! How cool is that!

你想要更多? 在那里。 打開模板文件后,將提示您輸入“開始年”和“結(jié)束年”的值,這意味著您可以自定義報(bào)告的時(shí)間范圍以進(jìn)行報(bào)告! 多么酷啊!

As soon as you enter values, Power BI will automatically create Date dimension for you, based on values you defined!

輸入值后,Power BI會(huì)根據(jù)您定義的值自動(dòng)為您創(chuàng)建日期維度!

結(jié)論 (Conclusion)

Power Query offers a whole range of features when it comes to data retrieval and especially for data transformation. Describing all of them will require a book or two, so I wanted to extract just a few of them which I consider most useful in my day-to-day work with Power BI.

Power Query在數(shù)據(jù)檢索(尤其是數(shù)據(jù)轉(zhuǎn)換)方面提供了廣泛的功能。 描述所有這些都需要一兩本書,因此我只想摘錄其中的一些,我認(rèn)為它們?cè)谂cPower BI的日常工作中最有用。

What are your favorite Power Query features? Feel free to share them in the Comments section.

您最喜歡的Power Query功能是什么? 隨時(shí)在“評(píng)論”部分中分享它們。

翻譯自: https://towardsdatascience.com/power-query-tips-for-every-power-bi-developer-da9ebd3dcd93

總結(jié)

以上是生活随笔為你收集整理的每个Power BI开发人员的Power Query提示的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。