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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Aidanok
New Member

Calculate totals of matching values in different columns

I'm newer to PowerBi and this is probably an easy solve for lots of people but I can't figure it out. I want to get the total times a value is present in a table when that value is in present in multiple colunms. 

 

Top table is example of table structure and bottom table is desired outcome.

 

Thank you in advance!

Aidanok_0-1709934799097.png

 

Desired outcome

Aidanok_1-1709934856837.png

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

Hi @Aidanok ,

 

@wini_R nice method! Thank you, for your quick response and the solution provided.
And based on the sample and description you provided, you can also consider the following method.
1.Please try code as below to create Calculated table.

Table = 
DISTINCT ( SELECTCOLUMNS ( 'Projectdetails', "Name", 'Projectdetails'[Lead] ) )

vweiyan1msft_0-1710135890280.png

2.Then use the following code to create a Calculated column.

Total projects assocated = 
VAR _Name = 'Table'[Name]
RETURN
    CALCULATE (
        COUNTROWS ( 'Projectdetails' ),
        FILTER (
            'Projectdetails',
            'Projectdetails'[Lead] = _Name
                || 'Projectdetails'[Support] = _Name
        )
    )

Result is as below.

vweiyan1msft_1-1710135968510.png


Best Regards,
Yulia Yan


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

3 REPLIES 3
v-weiyan1-msft
Community Support
Community Support

Hi @Aidanok ,

 

@wini_R nice method! Thank you, for your quick response and the solution provided.
And based on the sample and description you provided, you can also consider the following method.
1.Please try code as below to create Calculated table.

Table = 
DISTINCT ( SELECTCOLUMNS ( 'Projectdetails', "Name", 'Projectdetails'[Lead] ) )

vweiyan1msft_0-1710135890280.png

2.Then use the following code to create a Calculated column.

Total projects assocated = 
VAR _Name = 'Table'[Name]
RETURN
    CALCULATE (
        COUNTROWS ( 'Projectdetails' ),
        FILTER (
            'Projectdetails',
            'Projectdetails'[Lead] = _Name
                || 'Projectdetails'[Support] = _Name
        )
    )

Result is as below.

vweiyan1msft_1-1710135968510.png


Best Regards,
Yulia Yan


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

Thank you for your response. This worked perfectly!!!

wini_R
Resolver III
Resolver III

Hi @Aidanok,
I would transform the source table in power query to get the expected result. Here is example query (you can paste it in advance editor):

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJKzEsFUkqxOtFKRkCGY14eTBQkZAzkOKWChHwTi7LBQiZwITDXFCYH5Zsh+CCzQELmcHNB+kAiFnARMNcSzSGGBkBWcGIu3CWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Lead = _t, Support = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> "")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Value"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"

 

And that's the outome:

wini_R_0-1709937499867.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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