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
kormosb
Helper III
Helper III

t-1 quarter DAX - missing values

Hi,

 

I am facing an issue I would like to get help with.

 

I woud like to calculate the value of the previous quarter with the following DAX:

 

 

Value T-1 = CALCULATE('Value'[Value T],DATEADD('Quarter'[Last day of Quarter],-1,QUARTER))​

 

 

As you can see in the picture there are some missing values for the previous quarters, but I don't know why.

issue.JPG

 

Can you help me find the problem?

 

Please find attached the pbix and excel files.

Files 

 

Kind regards,

Benjamin

 

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

Hi, @kormosb 

 

I'd like to suggest you create a calculated column and a measure as below.

Calculated column:

YearQuarter = [Year]*10+[Q]

Measure:

LastYearQuarter Value = 
var _yearquarter = SELECTEDVALUE('Quarter'[YearQuarter])
var _lastyearquarter = 
CALCULATE(
        MAX('Quarter'[YearQuarter]),
        FILTER(
            ALL('Quarter'),
            'Quarter'[YearQuarter]<_yearquarter
        )
)
return
IF(
    NOT(ISBLANK(_lastyearquarter)),
    CALCULATE(
        SUM('Value'[Value]),
        FILTER(
            ALL('Quarter'),
            'Quarter'[YearQuarter] = _lastyearquarter
        )
    )
)

 

Result:

b1.PNG

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @kormosb 

 

I'd like to suggest you create a calculated column and a measure as below.

Calculated column:

YearQuarter = [Year]*10+[Q]

Measure:

LastYearQuarter Value = 
var _yearquarter = SELECTEDVALUE('Quarter'[YearQuarter])
var _lastyearquarter = 
CALCULATE(
        MAX('Quarter'[YearQuarter]),
        FILTER(
            ALL('Quarter'),
            'Quarter'[YearQuarter]<_yearquarter
        )
)
return
IF(
    NOT(ISBLANK(_lastyearquarter)),
    CALCULATE(
        SUM('Value'[Value]),
        FILTER(
            ALL('Quarter'),
            'Quarter'[YearQuarter] = _lastyearquarter
        )
    )
)

 

Result:

b1.PNG

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@kormosb , With date table you can get Last qtr like

 

QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(('Date'[Date])))

Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))

Last complete QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD( ENDOFQUARTER(dateadd('Date'[Date],-1,QUARTER))))
Last to last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-2,QUARTER)))
Next QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],1,QUARTER)))
Last year same QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,Year)))
Last year same QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(ENDOFQUARTER(dateadd('Date'[Date],-1,Year))))
trailing QTR = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,QUARTER))

 

 

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 :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...

In case you do not have date then you can use Qtr Rank to that

Same what I done for week -https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
Appreciate your Kudos.

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.