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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Longdisplay
Regular Visitor

PowerBI calculated measure - DAX

Hi Everyone, I have created a measure which calculates KPI based on selection in Slicer; when the particular product "A" or "B" or "C" is selected then the measure value returns, but when I have two different values selected in slicer like (A and B) - my calculated measure returns an error. My Slicer has distinct values like A,B,C to make selection. Please suggest - Below is my calculated measure :

TARGET =
IF (
    ISCROSSFILTERED ( Product[Product_Type] ),
    SWITCH (
        TRUE (),
        VALUES ( Product[Product_Type] ) = "A",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] ), RM[STATE] <> "TX"YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.10
            )
                + (
                    (
                        CALCULATE ( SUM ( RM[Dollar] ), RM[STATE] = "TX"YEAR ( RM[Date] ) = 2020 ) / 12
                    ) * ( 0.43 )
                ),
        VALUES ( Product[Product_Type] ) = "B",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] )YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.07
            ),
        VALUES ( Product[Product_Type] ) = "C",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] )YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.10
            ),
        BLANK ()
    ),
    BLANK ()
)

@Greg_Deckler,@v-jiascu-msft @Anonymous @selimovd @Fowmy @amitchandak @parry2k @Jihwan_Kim 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Longdisplay I will revisit this measure and maybe rewrite it this way. Again, please double-check the results.

 

 

TARGET =
IF (
    ISCROSSFILTERED ( Product[Product_Type] ),
    SUMX ( VALUES ( Product[Product_Type] ) ),
    
    SWITCH (
        Product[Product_Type],
        "A",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] ), RM[STATE] <> "TX", YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.10
            )
                + (
                    (
                        CALCULATE ( SUM ( RM[Dollar] ), RM[STATE] = "TX", YEAR ( RM[Date] ) = 2020 ) / 12
                    ) * ( 0.43 )
                ),
       "B",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] ), YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.07
            ),
       "C",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] ), YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.10
            ),
        BLANK ()
    ) --switch closing
    ), --sumx closing
    BLANK ()
)

 

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@Jihwan_Kim But that is not a true fix, it will not work if user selects more than one value, better to have multiple values selected, and show sum as @Longdisplay illustrated in his screenshot. Just my 2 cents. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Jihwan_Kim
Super User
Super User

In my opinion, instead of using VALUES, try using SELECTEDVALUES.

In that case, I think, if more than two products are selected in the slicer, it will return a blank.



Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



parry2k
Super User
Super User

@Longdisplay I will revisit this measure and maybe rewrite it this way. Again, please double-check the results.

 

 

TARGET =
IF (
    ISCROSSFILTERED ( Product[Product_Type] ),
    SUMX ( VALUES ( Product[Product_Type] ) ),
    
    SWITCH (
        Product[Product_Type],
        "A",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] ), RM[STATE] <> "TX", YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.10
            )
                + (
                    (
                        CALCULATE ( SUM ( RM[Dollar] ), RM[STATE] = "TX", YEAR ( RM[Date] ) = 2020 ) / 12
                    ) * ( 0.43 )
                ),
       "B",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] ), YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.07
            ),
       "C",
            (
                (
                    CALCULATE ( SUM ( RM[Dollar] ), YEAR ( RM[Date] ) = 2020 ) / 12
                ) * 1.10
            ),
        BLANK ()
    ) --switch closing
    ), --sumx closing
    BLANK ()
)

 

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

selimovd
Super User
Super User

Hey @Longdisplay ,

 

you get the error because you are checking with multiple selections a list returned by VALUES to a string, for example "A".

As long as there is only one value that works as it's transformed to a single row, but when there are more values you will get an error.

 

First I would change the VALUES ( Product[Product_Type] ) to MAX( Product[Product_Type] ). This should fix the error.

 

If you really want to select only one value, I would already change the slicer to single selection:

selimovd_0-1624950443365.png

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

Hi @selimovd ; I am getting inaccurate total from calculated measure when I have Product A and Product B Selected together - for example 

Total (from measure)       143,661
Product A       129,642
Product B          17,555
Accurate Total should be       147,197

 

Can you please suggest? 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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