Forum Discussion
Comparing multiple columns as rows
- Anonymous4 years ago
Hi lpd82 ,
Based on my test,
1. Create a new table with summarized data
Table = VAR _T = CROSSJOIN ( { "Sum of Sales", "Sum of COS", "Sum of GP" }, VALUES ( Data[Month] ) ) RETURN ADDCOLUMNS ( _T, "Sum", VAR _m = [Month] RETURN SWITCH ( [Value], "Sum of Sales", CALCULATE ( SUM ( Data[Sales] ), FILTER ( 'Data', 'Data'[Month] = _m ) ), "Sum of COS", CALCULATE ( SUM ( Data[COS] ), FILTER ( 'Data', 'Data'[Month] = _m ) ), "Sum of GP", CALCULATE ( SUM ( Data[GP] ), FILTER ( 'Data', 'Data'[Month] = _m ) ) ) )2. As you mentioned, you have two slicers to select months and you want to dynamically change the column/measure names.
To be more effective, I'd suggest you use only one slicer for multiple selections:
Var = VAR _min = MIN ( 'Table'[Month] ) VAR _max = MAX ( 'Table'[Month] ) RETURN IF ( HASONEVALUE ( 'Table'[Month] ), MAX ( 'Table'[Sum] ), CALCULATE ( MAX ( 'Table'[Sum] ), FILTER ( 'Table', 'Table'[Month] = _max ) ) - CALCULATE ( MAX ( 'Table'[Sum] ), FILTER ( 'Table', 'Table'[Month] = _min ) ) )Here is the final output :
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi lpd82 ,
Based on my test,
1. Create a new table with summarized data
Table =
VAR _T =
CROSSJOIN (
{ "Sum of Sales", "Sum of COS", "Sum of GP" },
VALUES ( Data[Month] )
)
RETURN
ADDCOLUMNS (
_T,
"Sum",
VAR _m = [Month]
RETURN
SWITCH (
[Value],
"Sum of Sales", CALCULATE ( SUM ( Data[Sales] ), FILTER ( 'Data', 'Data'[Month] = _m ) ),
"Sum of COS", CALCULATE ( SUM ( Data[COS] ), FILTER ( 'Data', 'Data'[Month] = _m ) ),
"Sum of GP", CALCULATE ( SUM ( Data[GP] ), FILTER ( 'Data', 'Data'[Month] = _m ) )
)
)
2. As you mentioned, you have two slicers to select months and you want to dynamically change the column/measure names.
To be more effective, I'd suggest you use only one slicer for multiple selections:
Var =
VAR _min =
MIN ( 'Table'[Month] )
VAR _max =
MAX ( 'Table'[Month] )
RETURN
IF (
HASONEVALUE ( 'Table'[Month] ),
MAX ( 'Table'[Sum] ),
CALCULATE ( MAX ( 'Table'[Sum] ), FILTER ( 'Table', 'Table'[Month] = _max ) )
- CALCULATE ( MAX ( 'Table'[Sum] ), FILTER ( 'Table', 'Table'[Month] = _min ) )
)
Here is the final output :
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Eyelyn - thank you for the great efforts. I also need a variance column for the selected periods, any suggestions?
Thanks again.