Forum Discussion

MichaelNiederer's avatar
MichaelNiederer
New Member
10 months ago
Solved

Switch function not working with a slicer

I have a Customer Sales Table with a sum (netSum = SUM(...)) and compare it with a sum of previous time period:

netSumPrev = CALCULATE(
     [netSum],
     ALL ( 'Date(Sales)' ),
     USERELATIONSHIP( 'Date(Sales)'[Date], 'DatePrev(Sales)'[Date] )
)
 
To filter the results regarding customer groups i wanted to add a slicer for grouping netSumPrev (e.g. for ranges 0-200 / 200-2000 / 2000+) and display only the customers which had specific turnovers in previous period.
I kinda ended up like in this topic (switch on customer group table - text values & SelectedValue which doesn't seem to work):
and would be interested, how to solve such a task 😉 - i could not access the solution any more.
 
Can you please give me hints about which measure functions you could use to solve this relation?
 
Thank you,
kind regards
  • MFelix's avatar
    MFelix
    9 months ago

    Hi MichaelNiederer ,

     

    The problem is that you have created a column on your model instead of a measure you create the following measure:

     

    Prev_Selection_SwitchCG _1 = 
    SWITCH(TRUE(),
    [NetSumPrev] >= MIN(CategoryDelNotes[Min]) && [NetSumPrev] < MAX(CategoryDelNotes[MAXREVISED]), 1)

    Now you should be able to get the result you need.

     

    Be aware that since your max value is blank I created a new column replacing blank by 9999999999

     

    Now if you use this measure on your visual you are able to get the expected result:

     

     

    If you just filter out the blanks you get the following result the bottom table is the one with the filter applied:

     

     

     

    Please see file attached.

     

7 Replies

  • Hi MichaelNiederer ,

     

    For this you need to have a table with the buckets and the switch statement, however you do not refer how that part of your model is.

     

    Can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

    If the information is sensitive please share it trough private message.

  • Hi, sorry for the delay, i needed some time to prepare example data manually.

    So i have some sales table (in original with DateTime column - so i could also use the PreviousDate Filter as a slider it seems - but seems similar with only Date at least) and a report where i display unique elements "DealerId + CustomerNr" (along with a summary of product group sums).

     

    My goal is to limit/filter the report to Combinations where Previous Date SalesSum is within some range - so i can filter important customers which i loose completely e.g. I tried with a switch statement to NetSum Previous Year like suggested but this does not filter anything.

    Is this not working properly, because mixing with product groups in the report? I think i am missing something.

     

    example report with demo data:

    https://we.tl/t-mInkBL5CJB

     

    Thank you for your help.

     

    Kind regards

      • MFelix's avatar
        MFelix
        Super User

        Hi MichaelNiederer ,

         

        The problem is that you have created a column on your model instead of a measure you create the following measure:

         

        Prev_Selection_SwitchCG _1 = 
        SWITCH(TRUE(),
        [NetSumPrev] >= MIN(CategoryDelNotes[Min]) && [NetSumPrev] < MAX(CategoryDelNotes[MAXREVISED]), 1)

        Now you should be able to get the result you need.

         

        Be aware that since your max value is blank I created a new column replacing blank by 9999999999

         

        Now if you use this measure on your visual you are able to get the expected result:

         

         

        If you just filter out the blanks you get the following result the bottom table is the one with the filter applied:

         

         

         

        Please see file attached.