Forum Discussion

Marico's avatar
Marico
Helper IV
3 years ago
Solved

Dax Calculation

I have a scenario like the below and need help to build the DAX logic for the same

Explanation: At the product level, Year1 is calculated as Launch date + 1 (year), Year 2 is calculated as Launch date + 2 (years), Year 3 is calculated as Launch date + 3 (years), so on and so forth till year 5.

Visualisation: The graph would look similar to above where in line chart x axis would have year1, year2, year3, year4 & year 5 and y axis would have no of products for that particular year

Sample Data:

 

 

 

Greg_Deckler amitchandak lbendlin Ashish_Mathur parry2k Jihwan_Kim tamerj1 DataInsights PaulDBrown johnt75 

  • If you can add a calculated column to your sales table you could use something like,

    Product Year =
    var _launchDate =
    LOOKUPVALUE(launchTable[Launch Date],launchTable[Product],salesTable[Product])
    var _elapsedDays =
    DATEDIFF(_launchDate,salesTable[SalesDate],year)+1
    Return
    SWITCH(
        _elapsedDays,
        1, "Year 1",
        2, "Year 2",
        3, "Year 3",
        4, "Year 4",
        5, "Year 5",
        "Year 6+"
    )
    To create a product year column that you could use in your visuals.

1 Reply

  • If you can add a calculated column to your sales table you could use something like,

    Product Year =
    var _launchDate =
    LOOKUPVALUE(launchTable[Launch Date],launchTable[Product],salesTable[Product])
    var _elapsedDays =
    DATEDIFF(_launchDate,salesTable[SalesDate],year)+1
    Return
    SWITCH(
        _elapsedDays,
        1, "Year 1",
        2, "Year 2",
        3, "Year 3",
        4, "Year 4",
        5, "Year 5",
        "Year 6+"
    )
    To create a product year column that you could use in your visuals.