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

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.

Reply
Anonymous
Not applicable

Adding a Dynamic Calculation

I have the following formula.  It returns the sum of my raw volume columns base on a slicer selection.  

 

I need to add another slicer that has Raw cases and Equivalent Cases.  If the user selects Raw cases- I need to multiple the volume by 1 or do nothing. If the user selects EQ, I need to multiple at the row level, each row in my data set by a field i have in my dataset called "192oz Conversion Factor" . Any help would be great.  Thanks

Selected Period Volume = 
VAR SPVOLUME =
SELECTEDVALUE ( 'Period Select (2)'[Period Selector])
RETURN
SWITCH (
SPVOLUME,
"YTD",SUM('Power BI Output'[YTD Volume]),
"MTD", SUM('Power BI Output'[MTD Volume]),
"2019", Sum('Power BI Output'[2019 Volume]),
"Rolling 13 Weeks", SUM('Power BI Output'[Rolling 13 Week Volume]),
"Pre-Covid W1-W9", SUM('Power BI Output'[Pre Covid First 9 Wks Volume]),
"Prior 4wks", SUM('Power BI Output'[Current 4 Week Volume]),
"Prior 13wks", SUM('Power BI Output'[Current 13 Week Volume]),
"Prior 26wks", SUM('Power BI Output'[Current 26 Week Volume]),
"Prior 52wks", SUM('Power BI Output'[Current 52 Week Volume]))

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @Anonymous 

Using another switch and SUMX should get you what you are looking for.  I don't know what the name of the table is where the user selection for "RAW" or "EQ" sits so you will have to update that.

Selected Period Volume Converted =
VAR SPVOLUME = SELECTEDVALUE ( 'Period Select (2)'[Period Selector] )
VAR CONVERSION = SELECTEDVALUE ( 'Conversion Table'[Conversion Rate] )
RETURN
    SWITCH (
        CONVERSION,
        "RAW",
            SWITCH (
                SPVOLUME,
                "YTD", SUM ( 'Power BI Output'[YTD Volume] ),
                "MTD", SUM ( 'Power BI Output'[MTD Volume] ),
                "2019", SUM ( 'Power BI Output'[2019 Volume] ),
                "Rolling 13 Weeks", SUM ( 'Power BI Output'[Rolling 13 Week Volume] ),
                "Pre-Covid W1-W9", SUM ( 'Power BI Output'[Pre Covid First 9 Wks Volume] ),
                "Prior 4wks", SUM ( 'Power BI Output'[Current 4 Week Volume] ),
                "Prior 13wks", SUM ( 'Power BI Output'[Current 13 Week Volume] ),
                "Prior 26wks", SUM ( 'Power BI Output'[Current 26 Week Volume] ),
                "Prior 52wks", SUM ( 'Power BI Output'[Current 52 Week Volume] )
            ),
        "EQ",
            SWITCH (
                SPVOLUME,
                "YTD",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[YTD Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "MTD",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[MTD Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "2019",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[2019 Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Rolling 13 Weeks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Rolling 13 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Pre-Covid W1-W9",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Pre Covid First 9 Wks Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Prior 4wks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Current 4 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Prior 13wks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Current 13 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Prior 26wks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Current 26 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Prior 52wks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Current 52 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    )
            )
    )

 

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@Anonymous First, daxformatter.com is your friend! 🙂 Second, if I understand correctly I think the below calculation should work. If not @ me and post sample data and expected output as text. Thanks!

Selected Period Volume =
VAR SPVOLUME =
    SELECTEDVALUE ( 'Period Select (2)'[Period Selector] )
RETURN
  IF(SPVOLUME = "Raw cases",
    SWITCH (
        SPVOLUME,
        "YTD", SUM ( 'Power BI Output'[YTD Volume] ),
        "MTD", SUM ( 'Power BI Output'[MTD Volume] ),
        "2019", SUM ( 'Power BI Output'[2019 Volume] ),
        "Rolling 13 Weeks", SUM ( 'Power BI Output'[Rolling 13 Week Volume] ),
        "Pre-Covid W1-W9", SUM ( 'Power BI Output'[Pre Covid First 9 Wks Volume] ),
        "Prior 4wks", SUM ( 'Power BI Output'[Current 4 Week Volume] ),
        "Prior 13wks", SUM ( 'Power BI Output'[Current 13 Week Volume] ),
        "Prior 26wks", SUM ( 'Power BI Output'[Current 26 Week Volume] ),
        "Prior 52wks", SUM ( 'Power BI Output'[Current 52 Week Volume] )
    ),
    SWITCH (
        SPVOLUME,
        "YTD", SUMX ( 'Power BI Output',[YTD Volume]*[192oz Conversion Factor] ),
        "MTD", SUMX ( 'Power BI Output',[MTD Volume]*[192oz Conversion Factor] ),
        "2019", SUMX ( 'Power BI Output',[2019 Volume]*[192oz Conversion Factor] ),
        "Rolling 13 Weeks", SUMX ( 'Power BI Output',[Rolling 13 Week Volume]*[192oz Conversion Factor] ),
        "Pre-Covid W1-W9", SUMX ( 'Power BI Output',[Pre Covid First 9 Wks Volume]*[192oz Conversion Factor] ),
        "Prior 4wks", SUMX ( 'Power BI Output',[Current 4 Week Volume]*[192oz Conversion Factor] ),
        "Prior 13wks", SUMX ( 'Power BI Output',[Current 13 Week Volume]*[192oz Conversion Factor] ),
        "Prior 26wks", SUMX ( 'Power BI Output',[Current 26 Week Volume]*[192oz Conversion Factor] ),
        "Prior 52wks", SUMX ( 'Power BI Output',[Current 52 Week Volume]*[192oz Conversion Factor] )
    )
  )

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
jdbuchanan71
Super User
Super User

Hello @Anonymous 

Using another switch and SUMX should get you what you are looking for.  I don't know what the name of the table is where the user selection for "RAW" or "EQ" sits so you will have to update that.

Selected Period Volume Converted =
VAR SPVOLUME = SELECTEDVALUE ( 'Period Select (2)'[Period Selector] )
VAR CONVERSION = SELECTEDVALUE ( 'Conversion Table'[Conversion Rate] )
RETURN
    SWITCH (
        CONVERSION,
        "RAW",
            SWITCH (
                SPVOLUME,
                "YTD", SUM ( 'Power BI Output'[YTD Volume] ),
                "MTD", SUM ( 'Power BI Output'[MTD Volume] ),
                "2019", SUM ( 'Power BI Output'[2019 Volume] ),
                "Rolling 13 Weeks", SUM ( 'Power BI Output'[Rolling 13 Week Volume] ),
                "Pre-Covid W1-W9", SUM ( 'Power BI Output'[Pre Covid First 9 Wks Volume] ),
                "Prior 4wks", SUM ( 'Power BI Output'[Current 4 Week Volume] ),
                "Prior 13wks", SUM ( 'Power BI Output'[Current 13 Week Volume] ),
                "Prior 26wks", SUM ( 'Power BI Output'[Current 26 Week Volume] ),
                "Prior 52wks", SUM ( 'Power BI Output'[Current 52 Week Volume] )
            ),
        "EQ",
            SWITCH (
                SPVOLUME,
                "YTD",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[YTD Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "MTD",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[MTD Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "2019",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[2019 Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Rolling 13 Weeks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Rolling 13 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Pre-Covid W1-W9",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Pre Covid First 9 Wks Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Prior 4wks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Current 4 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Prior 13wks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Current 13 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Prior 26wks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Current 26 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    ),
                "Prior 52wks",
                    SUMX (
                        'Power BI Output',
                        'Power BI Output'[Current 52 Week Volume] * 'Power BI Output'[192oz Conversion Factor]
                    )
            )
    )

 

@jdbuchanan71 Apparently that message took me 4 minutes to write!! 😄


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.