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

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
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.