Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
cho
Helper I
Helper I

Converting YTD figures to monthly figures in PowerQuery

Hi Experts,

 

I have a sample table like below:

AccountCompanyTypePeriodYTD
001AAAB1202211   100
002AAAC1202211   200
001BBBC2202211   300
007FFFB1202212   200
009RRRC1202212   400
011AAAC2202212   500
007RRRB1202301   200
012DDDC1202301   300
008BBBC2202301

500

 

But these values are YTD values and I need to convert this to a MTD table like this:

AccountCompanyTypePeriodMTD
001AAAB1202201   100
002AAAC1202201   200
001BBBC2202201   300
007FFFB1202202   100
009RRRC1202202   200
011AAAC2202202   200
007RRRB1202301   200
012DDDC1202301   300
008BBBC2202301

   500

 

Can someone help?

 

 

1 ACCEPTED SOLUTION
meiwah
Resolver I
Resolver I

Hi Cho, unfortunately, my data source is not SQL base. I've found a solution using Power Query. 

 

1) Add a custom column for YearnMonth

2) Add a custom column for Month

3) Add a custom column for Sales YTD Prev, which is the Sales YTD of the previous month. Using 

try #"Sorted Rows"[Sales YTD] {[Month] - 2} otherwise 0

4) Compute the difference betw [Sales YTD] and [Sales YTD Prev]

meiwah_0-1680596869119.png

 

I can't upload the source pbix file. Pls contact me if anyone needs it

View solution in original post

5 REPLIES 5
meiwah
Resolver I
Resolver I

Hi Cho, unfortunately, my data source is not SQL base. I've found a solution using Power Query. 

 

1) Add a custom column for YearnMonth

2) Add a custom column for Month

3) Add a custom column for Sales YTD Prev, which is the Sales YTD of the previous month. Using 

try #"Sorted Rows"[Sales YTD] {[Month] - 2} otherwise 0

4) Compute the difference betw [Sales YTD] and [Sales YTD Prev]

meiwah_0-1680596869119.png

 

I can't upload the source pbix file. Pls contact me if anyone needs it

HAP
Regular Visitor

Hi Meiwah. Thanks for your solution. I'd like to ask to share the PBIX file if possible.

 

I have YTD value of multiple categories for each month. My fiscal year is from April to March. Is this solution can work for multiple categories ?

Hi HAP,

 

can pm me your email? I can't attach the file here 🙂

meiwah
Resolver I
Resolver I

Yes, can anyone pls help. I've the same problem. Thanks!

Hey @meiwah! I found a solution for this. 

I could not do this in Power Query and I feel there is no point of adding columns there.

 

What I did was, when loading data, I wrote a small SQL so from data source itself, I convert YTD figures to monthly values.
I used SQL functions like LAG(), OVER(), PARTITION BY().

cho_0-1680593655066.png

 

Another way is to add a monthly column in data source.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.