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
obriaincian
Resolver I
Resolver I

Group by measure with DATESBETWEEN

Hi All,

 

I am stuck and can't get my head around a measure I've developed.

 

What I want to do is create a table that shows the count of occurences within a certain month.

 

My Data

Product

Product    Report Date      Previous Expiry     New Expiry  Change in Dates     
CokeJan-2201-01-2401-01-24No Change
7UPJan-22 02-01-23 25-01-23 < 1 Month
FantaJan-22 02-01-23 25-01-23 < 1 Month
PepsiJan-2201-01-2401-01-24No Change
CokeFeb-2201-01-2401-01-24No Change
7UPFeb-22  25-01-23 25-03-23 No Change
FantaFeb-22  25-01-23 25-03-23 No Change
PepsiFeb-22 01-01-2401-01-24No Change
CokeMar-22 01-01-2401-01-24No Change
7UPMar-22  25-03-23 25-05-23 >1 Month
FantaMar-22  25-03-23 25-05-23 >1 Month
PepsiMar-2201-01-2401-04-24>1 Month

 

 

So that is my data. What I want to do is Filter on the report date column for last month (which is Mar-22 or filter for the max month in the date column) and then group the Change in Dates column and count.

 

Desired outcome is to create a matrix visual with the below

Change                 No. of occurences             
No Change1
>1 Month3
<1 Month0

 

 

The measure I'm currently using which doesn't work is:

CALCULATE(
COUNTA('Data'[Change in Dates]) ,DATEADD(Data[Report Date],-1,Month))
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@obriaincian , You need to create a date table and new dimension with distinct value Change in Dates nad join both with your table

 

For TI prefer the date table

CALCULATE(
COUNTA('Data'[Change in Dates]) ,DATEADD(Date[Date],-1,Month))
 
or
 
CALCULATE(
COUNTA('Data'[Change in Dates]) ,previousmonth(Date[Date]))
 
 
Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@obriaincian , You need to create a date table and new dimension with distinct value Change in Dates nad join both with your table

 

For TI prefer the date table

CALCULATE(
COUNTA('Data'[Change in Dates]) ,DATEADD(Date[Date],-1,Month))
 
or
 
CALCULATE(
COUNTA('Data'[Change in Dates]) ,previousmonth(Date[Date]))
 
 
Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Hi @amitchandak thank you for your input. I'm just not sure how to create a date table and new dimension with distinct value Change in Dates and join both with your table

@obriaincian , New table in Dax

Change in dates = distinct(Table[Change in dates])

 

Date =

Addcolumns(calendar(date(2020,01,01), date(2021,12,31) ), "Month no" , month([date])
, "Year", year([date])
, "Month Year", format([date],"mmm-yyyy")
, "Month year sort", year([date])*100 + month([date])
, "Month",FORMAT([Date],"mmmm")
, "Month sort", month([DAte])

)

 

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.