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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Distinct count with previous date criteria

Hi, can anyone help me to understand what logic I need to apply to my existing table in order to return correct data?

 

Example table with underlying data called 'Table 1';

MarjanCRO_0-1669824896416.png

 

This is my current visual/table created in Power BI based on the above table with the date slicer to return data for Quarter 3 only;

MarjanCRO_1-1669825035739.pngMarjanCRO_1-1669820411628.png

 

I need to return the count of distinct postcodes with the time period (Q3) BUT I need to check the previous years' (12 months) data that returned postcodes and if the specific postcodes were queried within 12 months before the start date of Q3 (1st July21), we need to exclude those from the total count for Q3.

 

Just to give you a better context:

I need to bill my clients quarterly based on the number of calls they make, BUT I don't want to charge them for duplicate calls (postcodes) that were made in the past 12 months before the start date of the quarter.

e.g. client 'ABC ltd' had a total of 73 calls in Q3 but i don't want to charge them for all 73 calls, I want to charge them for unique (distinct) postcodes/calls compared with the past 12 months before start of Q3 (from 1st July 2020 to July 2021). This way we would only charge them for the first search of the postcode each time they search it in a year. Hope that makes sense. 

 

Does anyone have any idea how to make this work? I guess I need to get all calls/postcodes from the quarter I am doing plus the 12 of calls/postcodes prior to that quarter and then return the distinct count of postcodes from that quarter with removed postcodes that were included in the 12 months prior data. How to do that?

 

Thanks,

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

I create a simple test file. and create a measure as follow:

Measure = 
COUNTROWS(EXCEPT(VALUES('Table'[ID]),
SUMMARIZE(FILTER(ALL('Table'),
[Date]<=MIN('Table'[Date])&&[Date]>=EDATE(MIN('Table'[Date]),-12)),[ID])))

the final show:

vyalanwumsft_0-1669862128677.png


Best Regards,
Community Support Team _ Yalan Wu
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

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

I create a simple test file. and create a measure as follow:

Measure = 
COUNTROWS(EXCEPT(VALUES('Table'[ID]),
SUMMARIZE(FILTER(ALL('Table'),
[Date]<=MIN('Table'[Date])&&[Date]>=EDATE(MIN('Table'[Date]),-12)),[ID])))

the final show:

vyalanwumsft_0-1669862128677.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @v-yalanwu-msft, thanks for this. Looks really good. I think I will be able to use this in my report.

 

Just one quick question about the measure you provided;

Does this measure return unique, distinct IDs? If not, what and where to add to the measure to return only distinct IDs?

 

Sorry, I am fairly new to Power BI DAX.

Thanks,

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Top Solution Authors