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
alexei7
Continued Contributor
Continued Contributor

DAX help

Hi guys,

 

I'm trying to create a DAX measure and hoping someone can help.

 

As a sample of some dummy date, my data is structured like this:

 

ReportDateProductCodeStoreStatusConcat Column
15/08/201810000ManchesterLive10000Live
15/08/201810000LondonLive10000Live
15/08/201810000BrightonLive10000Live
15/08/201815000LondonNot Live15000Not Live
15/08/201815000ManchesterNot Live15000Not Live
15/08/201817000LondonLive17000Live
16/09/201810000ManchesterLive10000Live
16/09/201810000LondonLive10000Live
16/09/201810000BrightonLive10000Live
16/09/201815000LondonLive15000Live
16/09/201815000ManchesterLive15000Live
16/09/201817000LondonLive17000Live
16/09/201820000LondonLive20000Live

 

What i'm trying to achieve is a metric to see in the previous month (i.e. September), how many new products there were.

A new product is defined as a product code which has its Status = "Live" and was not live in the month before (i.e. August) - either it didnt appear at all, or it had a different status.

 

My idea at resolving this was:

1) Create the concatenated column above joining the ProductCode and the Status

2) Creating a lookup column so that looks up from the concatenated column, to a filtered version of the above table for the month before (i.e. August)

3) A simple calculate formula, which would count the non-blank cells from the column created in step 2, filtered on previous month (i.e. September).

 

I have a date dimension which joins to the "ReportDate" column here. The data dimension includes two custom columns:

 

- "InlastMonth" (i.e. "Yes" for September 2018, "No" for all other dates)

- "TwoMonthsAgo" (i.e. "Yes" for August 2018, "No" for all other dates)

 

I'm stuck on step 2: "Creating a lookup column so that looks up from the concatenated column, to a filtered version of the above table for the month before ".

 

Can anyone help (either with this step, or with a better overall solution)?

 

Dummy model available here:

https://mega.nz/#!zLxxQaRY!FoJzxlXgGSxxxAecDP6iueBIps-0sIwTtYRIGxTWdMM

 

Thanks in advance

Alex

 

1 ACCEPTED SOLUTION

Hi @alexei7,

 

That case, please add a [Rank] column first.

Rank =
RANKX ( Products, Products[ReportDate],, ASC, DENSE )

Then, modify the formula in original post as below:

Column1 =
VAR previousstatus =
    LOOKUPVALUE (
        Products[Status],
        Products[ProductCode], Products[ProductCode],
        Products[Store], Products[Store],
        Products[Rank], Products[Rank] - 1
    )
RETURN
    IF ( previousstatus = BLANK () || previousstatus = "Not Live", "New", BLANK () )

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.

View solution in original post

4 REPLIES 4
v-yulgu-msft
Employee
Employee

Hi @alexei7,

 

I removed the relationship between data table and date dimension table. Then, create below calculated column:

Column1 =
VAR previousstatus =
    LOOKUPVALUE (
        Products[Status],
        Products[ProductCode], Products[ProductCode],
        Products[Store], Products[Store],
        Products[ReportDate].[MonthNo], Products[ReportDate].[MonthNo] - 1
    )
RETURN
    IF ( previousstatus = BLANK () || previousstatus = "Not Live", "New", BLANK () )

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.
alexei7
Continued Contributor
Continued Contributor

Hi @v-yulgu-msft,

 

Thank you for your reply.

 

Unfortunately this doesnt work - I do need the relationship between the data table and the date dimension table for other calculations in my model/report.

 

The formula you've provided only takes account of the month number and not the previous month, so if i introduced some more data, i get the following incorrect result:

 

 incorrect data.png

 

Here the calculation is taking about only of the month number, so August 2019 is presumed to be before September 2018.

 

Thanks

Alex

Hi @alexei7,

 

That case, please add a [Rank] column first.

Rank =
RANKX ( Products, Products[ReportDate],, ASC, DENSE )

Then, modify the formula in original post as below:

Column1 =
VAR previousstatus =
    LOOKUPVALUE (
        Products[Status],
        Products[ProductCode], Products[ProductCode],
        Products[Store], Products[Store],
        Products[Rank], Products[Rank] - 1
    )
RETURN
    IF ( previousstatus = BLANK () || previousstatus = "Not Live", "New", BLANK () )

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.
alexei7
Continued Contributor
Continued Contributor

I haven't tested this as the user changed requirements a little so I ended up solving this a different way.

 

Cheers for looking into it though.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.