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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.