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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Need help in calculating distinct key running count

Hi,

 

I am trying to get distinct key running count based on product Type. where the end date must take from date slider and start date should be static to first day in date table even though user adjust the start date. uploaded pbix & Excel files with sample data & business expecations scenarios in below link:

https://gofile.io/d/0RclQs

 

sample data & business expectation.jpg

Any help is much appreciated !!

 

Thank you 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous ,

 

Believe that your data is not correctly calculated since if you look only at 36528 you have the lines below:

 

MFelix_0-1607523553626.png

3 of the lines are before January 15 and you have two distinct ProductKEY in your summary you are presenting only 1 so if you can confirm the data on the filtered data would be great.

 

Regarding your issue believe you would be better serve using a before slicer that way people would not be abble to change the start date but having this has you have you can write your measure in the following way:

 

Distinct key Running count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Product Key] );
    FILTER (
        ALL ( 'Table'[Invoice Date] );
        'Table'[Invoice Date] <= MAX ( 'Date'[Date] )
    );
    USERELATIONSHIP ( 'Date'[Date]; 'Table'[Invoice Date] )
)

When you making a reference to the entire table has you have previously the context picks up all the line values and all the columns so when you take out some columns from your data you will get 9 for every single row. This has to do with the use of measures and their context.

 

One further question if you activate the relationship there is no need for the use relationship, and if you use that with the before slicer there isn't a need for a measure you can use the column Product Key directly.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @Anonymous ,

 

Believe that your data is not correctly calculated since if you look only at 36528 you have the lines below:

 

MFelix_0-1607523553626.png

3 of the lines are before January 15 and you have two distinct ProductKEY in your summary you are presenting only 1 so if you can confirm the data on the filtered data would be great.

 

Regarding your issue believe you would be better serve using a before slicer that way people would not be abble to change the start date but having this has you have you can write your measure in the following way:

 

Distinct key Running count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Product Key] );
    FILTER (
        ALL ( 'Table'[Invoice Date] );
        'Table'[Invoice Date] <= MAX ( 'Date'[Date] )
    );
    USERELATIONSHIP ( 'Date'[Date]; 'Table'[Invoice Date] )
)

When you making a reference to the entire table has you have previously the context picks up all the line values and all the columns so when you take out some columns from your data you will get 9 for every single row. This has to do with the use of measures and their context.

 

One further question if you activate the relationship there is no need for the use relationship, and if you use that with the before slicer there isn't a need for a measure you can use the column Product Key directly.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

yes, its 2 unique product keys. i twisted a logic little bit and worked as i expected.

 

Thanks you Miguel, you are awesome !!

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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