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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Data-Papa
Frequent Visitor

grouping by with DAX without losing link to original data

PARTY_IDDistinct Count of Flags
1111121
22222217
33333316
44444416
55555516
66666615
77777715
88888815
99999915
1010101015
12121212114
13131313114
14141414114
15151515114
16161616114
17171717114
18181818114
19191919114
20202020214
21221212114

 

I need to have some dax so that I can put the above into the following format for a clustered bar chart:

countofPARTY_IDDistinct Count of Flags
121
117
316
515
1014

 

 

i have succesfully got the data out in this format via SQL, but I do not want to lose the PARTY_ID so that I can keep the drill-through capability.

 

Thanks!

1 ACCEPTED SOLUTION

Hi,

In the first example,

Please try "don't summarize" [Distinct count of flags] column in the visualization.

 

Jihwan_Kim_0-1711684121496.png

 

 

Or,

if you do not have [Distincgt count of flags] column for the axis, like the second example,

please try something like the attached pbix file below.

Jihwan_Kim_0-1711684575830.png

 

 

 

Jihwan_Kim_1-1711684409808.png

 

Count of party measure: = 
VAR _distinctcountnumber =
    SELECTEDVALUE ( 'Axis calculated table'[Distinct Count of Flags] )
VAR _t =
    ADDCOLUMNS (
        VALUES ( Data[PARTY_ID] ),
        "@distinctcount", CALCULATE ( COUNTROWS ( DISTINCT ( Data[FLAG_ID] ) ) )
    )
VAR _resulttable =
    FILTER ( _t, [@distinctcount] = _distinctcountnumber )
RETURN
    COUNTROWS ( _resulttable )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi, I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1711562598736.png

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi @Jihwan_Kim , your screenshot shows the needed result but the solution doesn't work. Here is what happens when I do the solution: 

DataPapa_0-1711617460780.png

It just gives me the number of rows in the table and the count of distinct flags in that table.

 

Here is an example of the raw data:

 

PARTY_IDFLAG_ID
11111a
11111b
11111c
22222a
22222b
22222c
33333a
44444a
44444b
44444c
44444d
44444e
44444f
44444g
44444h
55555a
55555b
66666a
66666b
77777a
77777b
88888a
88888b
99999a
99999b

 

And here is the expected result for the above:

countofPARTY_IDDistinct Count of Flags
23
11
18
52


hope this makes sense!

Hi,

In the first example,

Please try "don't summarize" [Distinct count of flags] column in the visualization.

 

Jihwan_Kim_0-1711684121496.png

 

 

Or,

if you do not have [Distincgt count of flags] column for the axis, like the second example,

please try something like the attached pbix file below.

Jihwan_Kim_0-1711684575830.png

 

 

 

Jihwan_Kim_1-1711684409808.png

 

Count of party measure: = 
VAR _distinctcountnumber =
    SELECTEDVALUE ( 'Axis calculated table'[Distinct Count of Flags] )
VAR _t =
    ADDCOLUMNS (
        VALUES ( Data[PARTY_ID] ),
        "@distinctcount", CALCULATE ( COUNTROWS ( DISTINCT ( Data[FLAG_ID] ) ) )
    )
VAR _resulttable =
    FILTER ( _t, [@distinctcount] = _distinctcountnumber )
RETURN
    COUNTROWS ( _resulttable )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

thanks @Jihwan_Kim  that did it ! 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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