cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Uzi2019
Helper V
Helper V

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.

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 IV
Super User IV

@Uzi2019 , Try like

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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

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.

 

 

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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

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

 

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

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

 

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.