cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Datahungry Frequent Visitor
Frequent Visitor

DIRECT QUERY equivalent to SAMEPERIODLASTYEAR

Hi everyone,

 

I'm using a SQL DB (DirectQuery  mode) as a datasource for my report.

I have a DateTable and SalesTable.

My goal is to have a report with:

- 2 slicers: 1 for years; 1 for months

- 1 List visual with 3 columns: YearMonth, Sales Amt, SalesAmt Previous Year

 

I tried the following, according to some examples I found online:

 

Total SalesAmt PY  =
    CALCULATE(
        [Total SalesAmt],
        FILTER(
            ALL(DateTable[Date Value]),
            AND(
                DateTable[Date Value]>=EDATE(MIN(DateTable[Date Value]),-12),
                DateTable[Date Value]<=EDATE(MAX(DateTable[Date Value]),-12)
            )
        )
    )

 

The problem is that, if I select more than one non-consecutive month (let's say, Feb and May), since the formula uses MIN and MAX, the result of this formula will include Feb, Mar, Apr and May.

 

Could someone please let me know how to achieve this?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Datahungry Frequent Visitor
Frequent Visitor

Re: DIRECT QUERY equivalent to SAMEPERIODLASTYEAR

Thank you for the suggestion, I actually had enabled it already.

 

I resorted to using a more complex DAX formula because I was trying to find a workaround for the "Power bi expects a contiguous selection" issue.

However, it seems that, if I change the relationshipt between the Date dimention table and Sales from direction from "Both" to "Single" it works.

 

Best regards

View solution in original post

2 REPLIES 2
Microsoft v-yulgu-msft
Microsoft

Re: DIRECT QUERY equivalent to SAMEPERIODLASTYEAR

Hi @Datahungry,

 

You could enable the highlighted option to use SAMEPERIODLASTYEAR() in Direct Query mode.

1.PNG

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Datahungry Frequent Visitor
Frequent Visitor

Re: DIRECT QUERY equivalent to SAMEPERIODLASTYEAR

Thank you for the suggestion, I actually had enabled it already.

 

I resorted to using a more complex DAX formula because I was trying to find a workaround for the "Power bi expects a contiguous selection" issue.

However, it seems that, if I change the relationshipt between the Date dimention table and Sales from direction from "Both" to "Single" it works.

 

Best regards

View solution in original post

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors