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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Vijay08V
Helper III
Helper III

Need help with a DAX function

Hi,

 

I need some help with the DAX function for below logic

Problem statement : Need to bring a stacked bar chart visual where it shows total count of each category based on the latest Id number available for each dimension. Let me explain it with a sample data.

From below dataset, for the dimension - Customer there are totally 5 distinct elements. Now If I take the first element which is collaboration then as per the last ID which is Id 77 the category would be "Innovator". Moving on to the next element Confidence there is only one category transformer.Similary for the element Engagement as per latest Id 77 the category would be Innovator

 

Now considering only the first three elements of customer dimension . Total count of elements would be as below

 

Innovator - 2

Transformer -1

 

Expected output in the visual is as below

 

Vijay08V_2-1683893930475.png

 

Sample Data :

 

ElementCategoryIdDimensions
CollaborationInnovator77Customer
CollaborationTransformer74Customer
ConfidenceTransformer74Customer
EngagementInnovator77Customer
EngagementTransformer74Customer
ExperienceTransformer74Customer
GoToMarketInnovator77Customer
GoToMarketTransformer74Customer
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Vijay08V ,

 

I suggest you to add an index column by Element group in Power Query Editor. This will make the calculation easier, we need a number column or date column to confirm the order of priority.

For reference: Create Row Number for Each Group in Power BI using Power Query

New Table:

vrzhoumsft_0-1684219554015.png

Measure:

Count = 
CALCULATE(DISTINCTCOUNT('Table'[Element]),'Table'[Index] = 1)

Result is as below.

vrzhoumsft_1-1684219670027.png

 

Best Regards,
Rico Zhou

 

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
Anonymous
Not applicable

Hi @Vijay08V ,

 

I suggest you to add an index column by Element group in Power Query Editor. This will make the calculation easier, we need a number column or date column to confirm the order of priority.

For reference: Create Row Number for Each Group in Power BI using Power Query

New Table:

vrzhoumsft_0-1684219554015.png

Measure:

Count = 
CALCULATE(DISTINCTCOUNT('Table'[Element]),'Table'[Index] = 1)

Result is as below.

vrzhoumsft_1-1684219670027.png

 

Best Regards,
Rico Zhou

 

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

 

amitchandak
Super User
Super User

@Vijay08V , You can use a measure

 

Distinctcount(Table[Element])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Hi Amit - I tried using distinct count measure but its giving me total count of 8. However it should be 3 count for Inovator and 2 for Transformer element based on the latest Id number

Vijay08V_0-1683898467898.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.