Forum Discussion
How would I do a dynamic visualization to show for Current and Next 12 Months Total Sales.
- Anonymous4 years ago
Hi mick22 ,
Here are the steps you can follow:
1. Create calculated table2.
Table2:
Table 2 =
CALENDAR(MIN('Table'[StartDate]),MAX('Table'[EndDate]))
Create the calculated column in Table2:
Year1 = VALUE( FORMAT('Table 2'[Date],"yyyymm"))Year2 = VALUE( FORMAT('Table 2'[Date],"yyyymm"))2. Create calculated table3.
Table3:
Table 3 = DISTINCT('Table 2'[Year2])3. Create measure.
Flag = var _1=CALCULATE(SUM('Table'[CurrentMonthlyPrice]),FILTER(ALL('Table 2'),'Table 2'[Year1]>=VALUE( FORMAT(MAX('Table'[StartDate]),"yyyymm"))&&MAX('Table 3'[Year2])<=VALUE( FORMAT(MAX('Table'[EndDate]),"yyyymm")))) return IF( MAX('Table 3'[Year2])<=MAX('Table 2'[Year1]),_1 ,0)Total_Incorrect = var _table=SUMMARIZE('Table 2','Table 2'[Year1],"_value",[Flag]) return IF(HASONEVALUE('Table 2'[Year1]),[Flag],SUMX(_table,[_value]))4. Result:
Refer to:
https://community.powerbi.com/t5/Desktop/Create-Lower-Triangular-Matrix/m-p/854339
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi mick22 ,
Here are the steps you can follow:
1. Create calculated table2.
Table2:
Table 2 =
CALENDAR(MIN('Table'[StartDate]),MAX('Table'[EndDate]))
Create the calculated column in Table2:
Year1 =
VALUE( FORMAT('Table 2'[Date],"yyyymm"))Year2 =
VALUE( FORMAT('Table 2'[Date],"yyyymm"))
2. Create calculated table3.
Table3:
Table 3 =
DISTINCT('Table 2'[Year2])
3. Create measure.
Flag =
var _1=CALCULATE(SUM('Table'[CurrentMonthlyPrice]),FILTER(ALL('Table 2'),'Table 2'[Year1]>=VALUE( FORMAT(MAX('Table'[StartDate]),"yyyymm"))&&MAX('Table 3'[Year2])<=VALUE( FORMAT(MAX('Table'[EndDate]),"yyyymm"))))
return
IF(
MAX('Table 3'[Year2])<=MAX('Table 2'[Year1]),_1
,0)Total_Incorrect =
var _table=SUMMARIZE('Table 2','Table 2'[Year1],"_value",[Flag])
return
IF(HASONEVALUE('Table 2'[Year1]),[Flag],SUMX(_table,[_value]))
4. Result:
Refer to:
https://community.powerbi.com/t5/Desktop/Create-Lower-Triangular-Matrix/m-p/854339
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Liu Yang - So I got this working a bit better and it pretty much looks like your example output. The only problem I'm having is that it's adding up CurrentMonthlyPrice for months that it should not based on YEAR1/YEAR2 being outside of the range of StartDate and EndDate. I did update my example in original post to clarify and post correct calculations. Any idea on why this might be happening?