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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Uzi2019
Super User
Super User

How to select multiple values from filter and create condition base calculated field.

Hi Experts,

 

I want to do calculation based on filter selection. If user select "TW" the "new " should  display "3700" and if user select "Travel" the "new " should display "1200" or otherwise " Old column".

 

1)    Travel= IF(MAX([Product])="Travel",3700)

 

2)    TW= IF(MAX([Product])="TW",1200)

 

 3)   Old column = ( sum(A)+sum(B) ) / ( sum(C)+sum(D) ).

 

4)    new  =SWITCH(SELECTEDVALUE([product]),"Travel",[Travel],"TW",[Tw],[Old column])
* All Calculated fields are measure.
 
 

Capture.PNGCapture.PNGCapture.PNG

 

Everything is working fine if user select single value from filter. but if I select travel and TW it is showing incorrect result. 

Please guide me to solve this issue. because selectedvalue  only supports single value.


Thank you in advance.

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
1 ACCEPTED SOLUTION

Hi, @Uzi2019 

 

It’s my pleasure to answer for you.

According to your description, Do you want to calculate the sum of the values when a date contains multiple products.

You can try like this:

Measure =
VAR p =
    ALLSELECTED ( 'product' )
RETURN
    SUMX (
        SUMMARIZE (
            'product',
            'product'[Date],
            "test",
                VAR e = [Date]
                VAR a =
                    ADDCOLUMNS (
                        p,
                        "value", SWITCH ( [product], "Travel", [Travel], "TW", [TW], 1000 )
                    )
                VAR b =
                    SUMMARIZE (
                        a,
                        'product'[Date],
                        "sum", SUMX ( FILTER ( a, [Date] = EARLIER ( 'product'[Date] ) ), [value] )
                    )
                RETURN
                    SUMX ( FILTER ( b, [Date] = e ), [sum] )
        ),
        [test]
    )

v-janeyg-msft_0-1603436415684.png

v-janeyg-msft_1-1603436415687.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

6 REPLIES 6
amitchandak
Super User
Super User

@Uzi2019 , Try like

=SWITCH(true(),
maxx(filter(product, [product] ="Travel"),[product]) = "Travel",[Travel]
maxx(filter(product, [product] ="TW"),[product]) = "TW",[Tw]
,[Old column])

Hi @amitchandak 

 

Thank you for your reply. But it is not working showing value 1200 if i select other product like car n all. and Total sum is not showing.

Uzi2019_0-1603265836309.png

Uzi2019_1-1603265891797.png

Please guide how to resolve this issue.

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

@Uzi2019 ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Hi @amitchandak 

 

Basically there are 2 tables. Both are connect on key column. Rest of the condition is same as above I have mentioned.

 

This is product table

DateproductsalesKey column
1/2/2020Car20001/2/2020Car
2/3/2020health40002/3/2020Heatl
1/3/2020TW10001/3/2020TW
5/2/2020Home20005/2/2020Home
8/10/2020Car12008/10/2020Car
6/5/2020Health5006/5/2020Health
1/2/2020Home30001/2/2020Home
1/7/2020TW20001/7/2020TW
23/4/2020Travel300023/4/2020Travel

 

This is Primary key table

dateproductKey column
1/2/2020Car1/2/2020Car
2/3/2020Health2/3/2020Heatl
1/3/2020TW1/3/2020TW
5/2/2020Home5/2/2020Home
8/10/2020Car8/10/2020Car
6/5/2020Health6/5/2020Health
1/2/2020Home1/2/2020Home
21/7/2020TW21/7/2020TW
23/4/2020Travel23/4/2020Travel
1/2/2020Health1/2/2020Health
1/2/2020TW1/2/2020TW
1/3/2020Home1/3/2020Home

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Hi, @Uzi2019 

 

It’s my pleasure to answer for you.

According to your description, Do you want to calculate the sum of the values when a date contains multiple products.

You can try like this:

Measure =
VAR p =
    ALLSELECTED ( 'product' )
RETURN
    SUMX (
        SUMMARIZE (
            'product',
            'product'[Date],
            "test",
                VAR e = [Date]
                VAR a =
                    ADDCOLUMNS (
                        p,
                        "value", SWITCH ( [product], "Travel", [Travel], "TW", [TW], 1000 )
                    )
                VAR b =
                    SUMMARIZE (
                        a,
                        'product'[Date],
                        "sum", SUMX ( FILTER ( a, [Date] = EARLIER ( 'product'[Date] ) ), [value] )
                    )
                RETURN
                    SUMX ( FILTER ( b, [Date] = e ), [sum] )
        ),
        [test]
    )

v-janeyg-msft_0-1603436415684.png

v-janeyg-msft_1-1603436415687.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-janeyg-msft 
 Thank you for your time. Let me check your formula at my end ,will get back to you.

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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