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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Calulating against many different fields

I have a table called Trainer. It has the following integer fields tcd, tsp, tgoing, tcourse, thorse, t_val_rank,winpos,eventdate

 

So far I have the following measure

Total Wins = CALCULATE( SUM(TrainerStats[winpos]),FILTER('TrainerStats',TrainerStats[winpos]=1 && TrainerStats[t_val_rank]=1))

It works. It sums all the occasions when [winpos]= and [t_val_rank]=1 .

 

But I would like a measure that would calculate the sum of winpos for any given value of any of the above fields ie so [winpos]= 1 && [tcd] =1 or [tsp] =1 etc.

At this stage of my learning DAX I would be happy with achieving that, but ultimately I would like to calcuate any of the above fields against [winpos] but instead of being restricted to a value of 1 for [tcd] I would like to show where [tcd] = any value in the tdc field ie 2, 3 or 4.

This is day 3 of my Dax frustration, so any help would be appreciated. Thanks.

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Unpivot the value type columns in Power Query Editor except [winpos] column

= Table.Unpivot(#"Changed Type", {"tcd", "tsp", "tgoing", "tcourse", "thorse", "t_val_rank"}, "Attribute", "Value")

vyiruanmsft_1-1681702642654.png

2. Create a measure as below to get the sum of value

Total Wins = 
CALCULATE (
    SUM ( TrainerStats[Value] ),
    FILTER (
        'TrainerStats',
        TrainerStats[winpos] = 1
            && TrainerStats[Attribute]
                IN ALLSELECTED ( 'TrainerStats'[Attribute] )
                    && 'TrainerStats'[Value] IN ALLSELECTED ( 'TrainerStats'[Value] )
    )
)

vyiruanmsft_0-1681702557708.png

 

If the above one can't help you get the expected result, could you please provide some raw data in the table 'TrainerStats' (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

Community Support Team _ Rena
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

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Unpivot the value type columns in Power Query Editor except [winpos] column

= Table.Unpivot(#"Changed Type", {"tcd", "tsp", "tgoing", "tcourse", "thorse", "t_val_rank"}, "Attribute", "Value")

vyiruanmsft_1-1681702642654.png

2. Create a measure as below to get the sum of value

Total Wins = 
CALCULATE (
    SUM ( TrainerStats[Value] ),
    FILTER (
        'TrainerStats',
        TrainerStats[winpos] = 1
            && TrainerStats[Attribute]
                IN ALLSELECTED ( 'TrainerStats'[Attribute] )
                    && 'TrainerStats'[Value] IN ALLSELECTED ( 'TrainerStats'[Value] )
    )
)

vyiruanmsft_0-1681702557708.png

 

If the above one can't help you get the expected result, could you please provide some raw data in the table 'TrainerStats' (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Let me first apologise for not providing sample data, and then to thank you for time and effort. It's much appreciated, and as well as answering my initial question has helped enourmously in my understanding of power bi. Thank you again.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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