Forum Discussion

tkavitha911's avatar
tkavitha911
Icon for Helper III rankHelper III
9 months ago
Solved

need help for dax

I have a table with columns: Date, Market, and Potential_dem_Cost. I need to create two measures: Next Month Potential_dem_Cost Next-to-Next Month Potential_dem_Cost These measures should dynam...
  • amitchandak's avatar
    9 months ago

    tkavitha911 ,  You can use TI various options are 

    MTD = CALCULATE(AverageX(values('Date'[Date]), calculate(SUM(Table[Qunatity Produced])) ),DATESMTD('Date'[Date]))

    MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
    last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
    last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))
    MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
    last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
    last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

     

    Trailing last month = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,MONTH))

     


    next month Sales = CALCULATE(SUM(Sales[Sales Amount]),nextmonth('Date'[Date]))

     

    next t month = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],1,MONTH))

    Next MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],1,MONTH)))

    Power BI: Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/cyWVzAQF9YU?t=41169

    MTD, Last Month, Trailing month
    https://youtu.be/cyWVzAQF9YU?t=41662

  • wardy912's avatar
    9 months ago

    Hi tkavitha911 

     

     You need to use SELECTEDVALUE in your measures to dynamically work with the month selected in the filter

     

    Next Month Potential_dem_Cost =
    VAR SelectedMonth =
        SELECTEDVALUE('Date'[MonthNumber])
    VAR SelectedYear =
        SELECTEDVALUE('Date'[Year])
    VAR NextMonth =
        IF(SelectedMonth = 12, 1, SelectedMonth + 1)
    VAR NextYear =
        IF(SelectedMonth = 12, SelectedYear + 1, SelectedYear)
    RETURN
    CALCULATE(
        SUM('YourTable'[Potential_dem_Cost]),
        FILTER(
            ALL('Date'),
            'Date'[MonthNumber] = NextMonth &&
            'Date'[Year] = NextYear
        )
    )
    Next-to-Next Month Potential_dem_Cost =
    VAR SelectedMonth =
        SELECTEDVALUE('Date'[MonthNumber])
    VAR SelectedYear =
        SELECTEDVALUE('Date'[Year])
    VAR NextMonth =
        IF(SelectedMonth >= 11, SelectedMonth - 10, SelectedMonth + 2)
    VAR NextYear =
        IF(SelectedMonth >= 11, SelectedYear + 1, SelectedYear)
    RETURN
    CALCULATE(
        SUM('YourTable'[Potential_dem_Cost]),
        FILTER(
            ALL('Date'),
            'Date'[MonthNumber] = NextMonth &&
            'Date'[Year] = NextYear
        )
    )

    --------------------------------

    I hope this helps, please give kudos and mark as solved if it does!

     

    Connect with me on LinkedIn.

    Subscribe to my YouTube channel for Fabric/Power Platform related content!