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.
I created a measure that shows revenue from the 12 months before the last 12 months using DATEADD function. I put it in a MATRIX and it works fine when there are no row or column headings added to the MATRIX. (See below)
However, when I try to add a dimension to rows, it gives me the following error:
Does anyone know how to fix this? Thanks in advance!
Solved! Go to Solution.
Hi,
According to your description, i create a sample to test:
Then create a date slicer table:
Date Slicer = DISTINCT(SELECTCOLUMNS('Table',"Date",'Table'[Date]))
Then try this measure:
Measure =
var a = SELECTEDVALUE('Date Slicer'[Date])
return
CALCULATE(SUM('Table'[accrual_revenue]),DATESBETWEEN('Table'[Date],DATE(YEAR(a)-2,MONTH(a),DAY(a)),DATE(YEAR(a)-1,MONTH(a),DAY(a))))
When choosing one date in date slicer, the result shows the total revenue from the 12 months before the last 12 months based on the date selected:
Tips: In this case, i add a defined filter to the table visual to show the result more obviously.
Here is my test pbix file:
Hope this can help.
Best Regards,
Giotto Zhi
Hi,
According to your description, i create a sample to test:
Then create a date slicer table:
Date Slicer = DISTINCT(SELECTCOLUMNS('Table',"Date",'Table'[Date]))
Then try this measure:
Measure =
var a = SELECTEDVALUE('Date Slicer'[Date])
return
CALCULATE(SUM('Table'[accrual_revenue]),DATESBETWEEN('Table'[Date],DATE(YEAR(a)-2,MONTH(a),DAY(a)),DATE(YEAR(a)-1,MONTH(a),DAY(a))))
When choosing one date in date slicer, the result shows the total revenue from the 12 months before the last 12 months based on the date selected:
Tips: In this case, i add a defined filter to the table visual to show the result more obviously.
Here is my test pbix file:
Hope this can help.
Best Regards,
Giotto Zhi
@Anonymous
For all such calculation use a date calendar and join the Date of Calendar with your date.
Something like
Last YTD Sales = CALCULATE(sum('PL lines'[PL Line.1]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
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/
if you need more help make me @
Appreciate your Kudos.
@amitchandakThanks. I do have a date calendar thats joined to my table date. I believe your formula examples do not pull prior 12 months before the last 12 months.
This formula works fine except when a row dimension is added to the matrix.
@Anonymous
Yes when you view by few dimension not all dates world be there, Try if one of 2 works
Prior 12 mo Rev = Calculate(sum('TKD'[accrual_revenue]),DATESINPERIOD(Date[Date],ENDOFMONTH(DATEADD(TKD[Date],-12,MONTH)),-12,MONTH))
Prior 12 mo Rev = Calculate(sum('TKD'[accrual_revenue]),DATESINPERIOD(Date[Date],ENDOFMONTH(DATEADD(Date[Date],-12,MONTH)),-12,MONTH))
@amitchandakUnfortunately, they didn't work. I think it's the dateadd piece that breaks it. 😞
@Anonymous
I have one doubt, your calendar min date is less than the min date of the TKD table. Just check.
If not so, Create a sample where you can reproduce and share.
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 |
---|---|
104 | |
101 | |
79 | |
72 | |
64 |
User | Count |
---|---|
142 | |
108 | |
101 | |
81 | |
74 |