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
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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


thanks @Jihwan_Kim  that did it ! 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors