Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hello,
I am trying to calculate the previous month value of transactions with the following code :
Transactions PM =
VAR LastDayAvailable =
CALCULATE (
MAX ( TKT[TKT_DATE] ),
ALL ( TKT )
)
VAR CurrentDates =
FILTER (
VALUES ( Date[Date] ),
Date[Date] <= LastDayAvailable
)
VAR Result =
CALCULATE (
[Number of transactions],
PREVIOUSMONTH ( CurrentDates )
)
RETURN Result
The results are good concerning each indivudual months. However the totals are wrong as seen on screenshot.
Can you please help me on that ?
Mohammad
Solved! Go to Solution.
@Anonymous - This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376
Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907
@Anonymous , if you have date you can use time intelligence with date table
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
previous month value = CALCULATE(sum('table'[total hours value]),previousmonth('Date'[Date]))
Power BI — MTD
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
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.
Dear @amitchandak,
Thanks for the reply but your solution does not work for me.
As I said, my problem is with the totals and subtotals.
Regards,
Mohammad
@Anonymous , because the previous month is in context so grand total will on last month
try like
sumx(summarize(Table, Table[year], Table[Month],"_1",[Transactions PM]),[_1])
@Anonymous - This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376
Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907
Dear @Greg_Deckler,
Thank you very much, you put me on the right track.
Just add the following code in the return :
RETURN IF(HASONEVALUE(Date[Date_id_mois]);Result)
It works great !
Mohammad
User | Count |
---|---|
140 | |
113 | |
104 | |
73 | |
63 |
User | Count |
---|---|
135 | |
126 | |
110 | |
70 | |
61 |