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
Dailem
Frequent Visitor

Distinct Count with Filter- Year Minus 1,2

I'm trying to get a distinct count of accounts that are filtered to only include accounts with Amount > 0.  The measure below gives me that count based upon the existing slicer quarter that I have selected (I have a Calendar in my model, but then a reporting calendar which only shows quarter-end dates).  So my report is filtered to 9/30/2023, for example:

Measure1 =

CALCULATE(
DISTINCTCOUNT(Table1[AccountKey]),
FILTER(Table1, Table1[Amount] > 0))

 

...however, I am trying to look at this same measure one year ago, two years ago, etc..  I have another measure that looks at prior year sales by filtering using the following in a calculate function:

dateadd('Calendar'[Date],-1,year)

 

...I have tried to add a second filter, but I cannot seem to get it to work properly.  When it does work, it only returns the existing date distinct counts- not those from the prior year.  How can I add a date filter on top of my existing Measure1 above to return the prior year account counts?  Any help is greatly appreciated!!

 

1 ACCEPTED SOLUTION
Dailem
Frequent Visitor

I was able to resolve this on my own.  The way that I was able to get the result was to use the initial measure in a second measure.  So first measure is:

 

 

Measure1 =

CALCULATE(
DISTINCTCOUNT(Table1[AccountKey]),
FILTER(Table1, Table1[Amount] > 0))

 

...second measure is

Measure2 = 

CALCULATE(Measure1, dateadd('Calendar'[Date],-1,year))

 

...this returns the same distinct count of the accountkey column, but does so for the prior year.  Thanks for all who responded!!

View solution in original post

3 REPLIES 3
Dailem
Frequent Visitor

I was able to resolve this on my own.  The way that I was able to get the result was to use the initial measure in a second measure.  So first measure is:

 

 

Measure1 =

CALCULATE(
DISTINCTCOUNT(Table1[AccountKey]),
FILTER(Table1, Table1[Amount] > 0))

 

...second measure is

Measure2 = 

CALCULATE(Measure1, dateadd('Calendar'[Date],-1,year))

 

...this returns the same distinct count of the accountkey column, but does so for the prior year.  Thanks for all who responded!!

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but please try creating the semantic model's relationship between Calendar Table and Fact Table by using Calendar[Date] column, not Calendar[QuarterEndDate] column.


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

Hi @Dailem ,

Can you provide some example data that can be used to more clearly articulate the problem you are experiencing.  Please provide more details with your desired out put and pbix file without privacy information.

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

Best Regards,

Ada Wang

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

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.