Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
lpd82
Helper I
Helper I

Comparing multiple columns as rows

Howdy PBI GURUS! I'm having a hard time creating a comparison with multiple columns subtotal as rows. From the sample data below, I want to compare sales, cos and gp for two user selected period. Sales, cos, and gp are columns in the data set, I want to flip it and subtotal it as rows.


TIA!

Data:

Region Sales  COS  GP Month
West $  678.00 $  542.40 $  135.60May
East $  631.00 $  504.80 $  126.20May
North $  812.00 $  649.60 $  162.40May
South $  960.00 $  768.00 $  192.00May
West $  651.00 $  520.80 $  130.20June
East $  611.00 $  488.80 $  122.20June
North $  904.00 $  723.20 $  180.80June
South $  956.00 $  764.80 $  191.20June
West $  729.00 $  583.20 $  145.80July
East $  872.00 $  697.60 $  174.40July
North $  643.00 $  514.40 $  128.60July
South $  893.00 $  714.40 $  178.60July

 

Results:  User selected June from one slicer and July from another slicer

ValuesMayJulyVar
Sum of Sales34803176-304
Sum of COS27842540.8-243.2
Sum of GP696635.2-60.8
1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

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 ) )
                )
    )

New table.PNG

 

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 :

dynamic name.gif

 

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.

View solution in original post

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

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 ) )
                )
    )

New table.PNG

 

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 :

dynamic name.gif

 

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.

Greg_Deckler
Super User
Super User

@lpd82 Use the "Show measures on row" feature.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Greg,

 

Thanks for the prompt reply.  "show meaure on row" will put the sumation on rows, but how do I configure the user select on the measure for the comparison? 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.