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.
Hi,
I have a table with running sales by state by customer by date iterating down. I received some help with DAX measures to calculate the daily change and % change, however, the results are negative values when I try to aggregate up to state or even national. Here's my table sample:
Here is the fantastic DAX syntax for daily change and daily change % that @az38 constructed :
Daily Chg = var _prevDate = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Customer]=SELECTEDVALUE('Table'[Customer]) && 'Table'[Date]<SELECTEDVALUE('Table'[Date]))) RETURN IF(ISBLANK(_prevDate), BLANK(), SELECTEDVALUE('Table'[Running Sales])-CALCULATE(MAX('Table'[Running Sales]),FILTER(ALL('Table'),'Table'[Customer]=SELECTEDVALUE('Table'[Customer]) && 'Table'[Date]=_prevDate)))
% Daily Chg = var _prevDate = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Customer]=SELECTEDVALUE('Table'[Customer]) && 'Table'[Date]<SELECTEDVALUE('Table'[Date]))) RETURN IF(ISBLANK(_prevDate), BLANK(), DIVIDE(SELECTEDVALUE('Table'[Running Sales]), CALCULATE(MAX('Table'[Running Sales]),FILTER(ALL('Table'),'Table'[Customer]=SELECTEDVALUE('Table'[Customer]) && 'Table'[Date]=_prevDate))) - 1)
As you can see in the table example, when I remove the customer and display results by state, I get negative values. Anyone with ideas? I've spent the past day trying to figure this out. Thanks.
Solved! Go to Solution.
@parry2k yes those are the desired results. It just needs to scale to the agg level (State or National) in my visual.
@chamue329 I don't have older version but here are the steps,
ADd a calendar table in your model, called it Calendar and you can use following DAX expression to create one
Calendar = CALENDARAUTO()
and mark this new table as data table
set reltionship between date from calendar table with your data table, add following measures
Add following measures
RT Sum = SUM ( 'Table'[Running Sales] )
RT Sum Prev Day = CALCULATE ( [RT Sum], DATEADD ( 'Calendar'[Date], -1, DAY ) )
RT Diff = [RT Sum] - [RT Sum Prev Day]
on table visual, drop date from calendar table (very important) and then rest of the columns from your data table (state, customer etc) and above measures and you should be good to go.
Would appreciate Kudos 🙂 if my solution helped.
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.
Try Measure with a date calendar
Current = SUM(Sales[Running Sales])
//Or
Current = SUM(Sales[Running Sales], filter('Date','Date'[Date]=max('Date'[Date]))
Day behind Sales = CALCULATE(SUM(Sales[Running Amount]),dateadd('Date'[Date],-1,Day))
//OR
Day behind Sales = SUM(Sales[Running Sales], filter('Date','Date'[Date]=max('Date'[Date])-1))
diff =[Current] =Day behind Sales
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/
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
110 | |
91 | |
84 | |
66 |