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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ryan_mayu
Super User
Super User

Urgent! Need help!!

Hi , i have a sample data below.

1.JPG

 

How can I use DAX to get the below result?

I want to get the total sales in of pervious three months.

Jan=Jan,

Feb=Jan+Feb

Mar=Jan+Feb+Mar

....

Sep=Jul+Aug+Sep

 

2.JPG

 

 

Thanks in advanced.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




1 ACCEPTED SOLUTION

@ryan_mayu Here is the measure for same...

 

Test46Out = 
CALCULATE(SUM(Test46CummSum[Value]),FILTER(ALL(Test46CummSum),Test46CummSum[Date] <= MAX(Test46CummSum[Date]) && YEAR(Test46CummSum[Date]) = YEAR(MAX(Test46CummSum[Date])) && DATEDIFF(Test46CummSum[Date],MAX(Test46CummSum[Date]),MONTH)<=2 ))

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

7 REPLIES 7
PattemManohar
Community Champion
Community Champion

@ryan_mayu Please try this as a "New Table"

 

Test46Out = 
VAR _Temp = ADDCOLUMNS(Test46CummSum,"CummSum",CALCULATE(SUM(Test46CummSum[Value]),FILTER(Test46CummSum,Test46CummSum[Date]<=EARLIER(Test46CummSum[Date]) && DATEDIFF(Test46CummSum[Date],EARLIER(Test46CummSum[Date]),MONTH)<=2 )))
RETURN SELECTCOLUMNS(_Temp,"Month",[Month],"Total",[CummSum])

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




@PattemManohar,

 

thanks for your help. Is it possible to create a measure to draw a chart by month?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu Here is the measure for same...

 

Test46Out = 
CALCULATE(SUM(Test46CummSum[Value]),FILTER(ALL(Test46CummSum),Test46CummSum[Date] <= MAX(Test46CummSum[Date]) && YEAR(Test46CummSum[Date]) = YEAR(MAX(Test46CummSum[Date])) && DATEDIFF(Test46CummSum[Date],MAX(Test46CummSum[Date]),MONTH)<=2 ))

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




@PattemManohar,

 

Can I escalate this question?

 

I read your DAX, it works in a year. What about Jan 2019= Nov 2018+Dec 2018+Jan 2019?

 

Do you have any idea on how to solve this problem?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu Yes, Ofcourse !! In that case, try the same DAX by removing the YEAR condition in the FILTER.





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




@PattemManohar, I will try that. Thanks a lot.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks, it works.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.