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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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