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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Date Functions- in measures

Hello, 

 

I have created some measures to look at the count of deliveries in the last 3 months/last 6 months / last 12 months.

So if a delivery is from 2 months ago, it will be included in all three measures.

 

ACUNILIN_0-1620120218318.png

 

I want to now be able to replicate these measures, but instead of looking at the last 6 months, I want to see deliveries between the last 3-6 months, and between the last 6-12 months.

So that the deliveries are split into buckets of 0-3, 3-6 & 6-12, without being double counted in any.

 

Can someone show me how this can be done in a similar way to the measures I have already? I do not want to create any calculated columns.

 

 

Many Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Please try to update the formula of measure [] and check whether you can get the desired result:

DeliveryItems_Last 03-06 Months =
VAR datestart =
    CALCULATE (
        DATEADD ( 'Calendar'[Date], -3MONTH ),
        ALL ( 'Calendar' ),
        'Calendar'[Is Current Day] = TRUE ()
    )
VAR datesend =
    CALCULATE (
        DATEADD ( 'Calendar'[Date], -6MONTH ),
        ALL ( 'Calendar' ),
        'Calendar'[Is Current Day] = TRUE ()
    )
RETURN
    CALCULATE (
        COUNT ( 'Transportation Cost'[MaterialKey] ),
        Material[Material Group HL] = "Laminate"
            || Material[Material Group HL] = "Vinyl"
            || Material[Material Group HL] = "Wood",
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] >= datestart
                && 'Calendar'[Date] <= datesend
        ),
        'Customer Sales'[Customer Group] <> "99"
            && 'Customer Sales'[Customer Group] <> "90"
            && 'Customer Sales'[Customer Group] <> "91"
    )

If the above one is not working in your scenario, please provide some sample data(exclude sensitive data) and your expected result with examples. By the way, what's the data type of field  'Calendar'[Date short]? Its data type is Date or some else type? Thank you.

Best Regards

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , Make your datetoday  formula the same as date fromcal and subtract 3 months when you need 3-6

 

You can also try like

examples

Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date]),0),-3,MONTH))
Rolling 3 before 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date]),-3),-3,MONTH))

 

Rolling 6 before 6 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date]),-6),-6,MONTH))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak ,

 

I tried to replicate as you advised:

 

ACUNILIN_0-1620126289094.png

 

But I get the following error message about comparing Date & Text values,

 

What do I need to adjust to clear this message?

ACUNILIN_1-1620126354152.png

 

Many Thanks

 

@Anonymous , Use these calculation to get min and max date 

 

var _max1 = maxx(allselected('Date1'), 'Date1'[Date])
var _max = eomonth(_max1,-3)
var _min = eomonth(_max1,-6)+1

 

 

or

 
var _max1 = today()
var _max = eomonth(_max1,-3)
var _min = eomonth(_max1,-6)+1

 

make sure filter is applied on date 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak thanks for your help,

I am still struggling to determine where to add in the max/min date calculations, can you indicate where I should add these if I paste in the DAX text below?

 

DeliveryItems_Last 03-06 Months =
VAR datestart =
CALCULATE (
DATEADD ( 'Calendar'[Date], -3, MONTH ),
ALL ( 'Calendar' ),
'Calendar'[Is Current Day] = TRUE ()
)
VAR datefromcalc =
CALCULATE (
DATEADD ( 'Calendar'[Date], -6, MONTH ),
ALL ( 'Calendar' ),
'Calendar'[Is Current Day] = TRUE ()
)
VAR datefrom =
CALCULATE (
MAX ( 'Calendar'[Date short] ),
ALL ( 'Calendar' ),
'Calendar'[Date] = datefromcalc
)
RETURN
CALCULATE (
COUNT ( 'Transportation Cost'[MaterialKey] ),
 
Material[Material Group HL] = "Laminate"
|| Material[Material Group HL] = "Vinyl"
|| Material[Material Group HL] = "Wood",
 
FILTER (
ALL ( 'Calendar' ),
'Calendar'[Date short] <= datestart
&& 'Calendar'[Date short] >= datefrom
),
'Customer Sales'[Customer Group] <> "99" && 'Customer Sales'[Customer Group] <> "90" && 'Customer Sales'[Customer Group] <> "91")
 
 
Many Thanks
Anonymous
Not applicable

Hi @Anonymous ,

Please try to update the formula of measure [] and check whether you can get the desired result:

DeliveryItems_Last 03-06 Months =
VAR datestart =
    CALCULATE (
        DATEADD ( 'Calendar'[Date], -3MONTH ),
        ALL ( 'Calendar' ),
        'Calendar'[Is Current Day] = TRUE ()
    )
VAR datesend =
    CALCULATE (
        DATEADD ( 'Calendar'[Date], -6MONTH ),
        ALL ( 'Calendar' ),
        'Calendar'[Is Current Day] = TRUE ()
    )
RETURN
    CALCULATE (
        COUNT ( 'Transportation Cost'[MaterialKey] ),
        Material[Material Group HL] = "Laminate"
            || Material[Material Group HL] = "Vinyl"
            || Material[Material Group HL] = "Wood",
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] >= datestart
                && 'Calendar'[Date] <= datesend
        ),
        'Customer Sales'[Customer Group] <> "99"
            && 'Customer Sales'[Customer Group] <> "90"
            && 'Customer Sales'[Customer Group] <> "91"
    )

If the above one is not working in your scenario, please provide some sample data(exclude sensitive data) and your expected result with examples. By the way, what's the data type of field  'Calendar'[Date short]? Its data type is Date or some else type? Thank you.

Best Regards

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.