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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calculate DOS dynamically based on month

Hi,

Urgent help needed!

I have a table having Deal History coming in every month as below.

 

ReportMonthCodeDeal_DateValue
1/1/2020A1/12/201910
1/1/2020A23/11/201920
1/1/2020A3/11/201920
1/1/2020A15/10/201930
1/1/2020A8/9/201940
1/1/2020B2/11/201925
1/1/2020B3/12/201930
1/1/2020B5/10/201935
1/1/2020B8/9/201960
2/1/2020A1/12/201910
2/1/2020A23/11/201920
2/1/2020A15/10/201930
2/1/2020A1/9/202040
2/1/2020B2/11/201925
2/1/2020B3/12/201930
2/1/2020B1/10/202035
2/1/2020B5/10/201960

I need to  pivot for every month taking last 3 months values in consideration based on report month.

For ex:- below for 1/1/2020 i need sum values only for last 3 months from Jan i.e Oct, Nov and Dec.

same for 2/1/2020 ie for Feb-  sum of values for Nov, Dec and Jan. (ignore the inv column it is custom column)

MonthCodeSep-19Oct-19Nov-19Dec-19Jan-20Inv
1/1/2020A 304010 20
1/1/2020B 352530 30
2/1/2020A  20104025
2/1/2020B  25303550

 

Query 2:- If i get the above table format, i need to calculate DOH, as -

-> for month - 1/1/2020 - if(inv<=Dec19, inv/dec19 *31,if(inv<=(dec19+nov19),(inv-dec19)/nov19*(30+31)),if(inv<=(dec19+nov19+oct19),(inv-dec19-nov19)/oct19*(31+30+31)

-> for month - 2/1/2020 - if(inv<=jan20, inv/jan20 *31,if(inv<=(dec19+jan20),(inv-jan20)/dec19*(31+31)),if(inv<=(jan20+dec19+nov19),(inv-jan20-dec19-nov19)/nov19*(31+30+31)

 

So 2 things are dynamic in above formula. 

1. Based on report month, formula will take last 3 months values in consideration.

2. the number 30 or 31 is number of days in the months taken into consideration for comparison.

 

Any help appreciated. !

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , creata rolling formula with help of a date table

Rolling 3= CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],startofmonth(Sales[Sales Date])-1,-3,MONTH))

or

Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],max(Sales[Sales Date])-1,-3,MONTH))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak , thanks for your reply.

But i need to build this query in Query editor, because i need to do some processing of data and calculated column is not visible in query editor.

Is there any way for it?

Also can you please help with DOH calculation. ie. Query-2.

@Anonymous You cannot have dynamic calculation using power query, given @amitchandak solution works, you need to use this in DAX and that will make it dynamic?

 

What is your thought process that you need it in Power Query?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

I tried using the above formula, in it works in DAX. and it works to get the the running totals.

But my main concern is to calculate DOH using the running totals as below.

 

1. for month - 1/1/2020 -

=if(inv<=Dec19, inv/dec19 *31,if(inv<=(dec19+nov19),(inv-dec19)/nov19*(30+31)),if(inv<=(dec19+nov19+oct19),(inv-dec19-nov19)/oct19*(31+30+31)))

2. for month - 2/1/2020 -

=if(inv<=jan20, inv/jan20 *31,if(inv<=(dec19+jan20),(inv-jan20)/dec19*(31+31)),if(inv<=(jan20+dec19+nov19),(inv-jan20-dec19-nov19)/nov19*(31+30+31)))

 

and then i have a third table which needs to sumif the DOH for each code dynamically.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors