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

Fiscal QTD, DATESBETWEEN functions, and IF statements

Hey guys, 

 

I am a new Power BI user and I'm stumped by this problem. 

 

I'm trying to calculate the sum of invoice values in a sales table against the current date in a custom fiscal quarter (June-April FY).

 

My date table has columns outlining the fiscal quarter, fiscal startofquarter, and fiscal endofquarter. I had an idea to add IF statements to try determine what quarter today's date falls into. 

 

I've tried writing the DAX function below but i'm getting errors: 

ActualQTD = CALCULATE([Net Amount],
    DATESBETWEEN(
        'Date',
        IF('Date'[Date] = TODAY(), 'Date'[Fiscal StartOfQuarter]),
        IF('Date'[Date] = TODAY(), 'Date'[Fiscal EndOfQuarter])
    )
) 

 

What can I do to make this work? Any hint in the right direction would be amazing, thank you. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hey @Phil_Seamark

 

So I managed to figure this out. 

 

It helped that I was using SQLBI's Dax Date table, which includes a date for the start/end of fiscal quarter, month and year.

 

I began by creating the following measures:

 

Start Of  Fiscal Quarter = CALCULATE(MIN('d Date'[F.QuarterStart]), ('d Date'[date] = TODAY()))

 

End Of Fiscal Quarter = CALCULATE(MIN('d Date'[F.QuarterEnd]), ('d Date'[date] = TODAY()))

 

I then employed the DATESBETWEEN FUNCTION in the following measure: 

 

ActualQTD = CALCULATE([Net Amount],
DATESBETWEEN(
'd Date'[Date],
[Start Of Fiscal Quarter],
[End Of Fiscal Quarter]
)
)

 

Doing this has allowed The Actual QTD number to stay current based on the current quarter. I repeated this for the fiscal month and year it all worked out nicely. 

 

Cheers, 

 

View solution in original post

3 REPLIES 3
Phil_Seamark
Employee
Employee

Hi @Anonymous

 

Does this slight mod help?

 

 

ActualQTD = 
    TOTALQTD([Net Amount],'Date'[Date])

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Hey @Phil_Seamark, this is almost exactly the DAX statement I had before. 

What i had before was this: 

ActualQTD = CALCULATE([Net Amount], DATESQTD('Date'[Date]))

The problem here is that the DATESQTD function is based on the calendar year, and not the Fiscal (at least, I think that's the case). 

The error I'm receiving from PBI for the original DAX function I wrote is this: 

*DatesBetween and DatesInPeriod functions are only accepting date column reference as a first argument*

Anonymous
Not applicable

Hey @Phil_Seamark

 

So I managed to figure this out. 

 

It helped that I was using SQLBI's Dax Date table, which includes a date for the start/end of fiscal quarter, month and year.

 

I began by creating the following measures:

 

Start Of  Fiscal Quarter = CALCULATE(MIN('d Date'[F.QuarterStart]), ('d Date'[date] = TODAY()))

 

End Of Fiscal Quarter = CALCULATE(MIN('d Date'[F.QuarterEnd]), ('d Date'[date] = TODAY()))

 

I then employed the DATESBETWEEN FUNCTION in the following measure: 

 

ActualQTD = CALCULATE([Net Amount],
DATESBETWEEN(
'd Date'[Date],
[Start Of Fiscal Quarter],
[End Of Fiscal Quarter]
)
)

 

Doing this has allowed The Actual QTD number to stay current based on the current quarter. I repeated this for the fiscal month and year it all worked out nicely. 

 

Cheers, 

 

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.