Forum Discussion

jeanbinhozouza's avatar
4 years ago
Solved

Consumption dax

  • Hi jeanbinhozouza 

    Thanks for reaching out to us.

    >>The problem arises when I change the date to get last week's consumption of parts, in this case even having previous consumption, the horimetropenultimatroca column does not show the values ​​because it ends up filtering the date.

    The usual practice is to create a separate calendar table, then use the date in the calendar for the slicer, and then get the date range in the slicer to calculate the horimetropenultimatroca.

    for example, create the 2 measures below to get the date range in slicer

    selectedRange_start= minx(allselected('calendar'),[date])

    selectedRange_end= maxx(allselected('calendar'),[date])

    then, create a measure to calculate horimetropenultimatroca, for example, you can time offset the obtained date range, use edate() or eomonth()

    FYI: 

    EDATE function (DAX) - DAX | Microsoft Docs

    EOMONTH function (DAX) - DAX | Microsoft Docs

    measure = 
    var _newstart= EDATE([selectedRange_start],-1)
    var _newend= EDATE([selectedRange_end],-1)
    return sumx(filter(all('fact table'),'fact table'[date]>=_newstart && 'fact table'[date]<=_newend), [sale])

    If you need more help, please let me know. 

     

    Best Regards,

    Community Support Team _Tang

    If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • v-xiaotang's avatar
    v-xiaotang
    Community Support

    Hi jeanbinhozouza 

    Thanks for reaching out to us.

    >>The problem arises when I change the date to get last week's consumption of parts, in this case even having previous consumption, the horimetropenultimatroca column does not show the values ​​because it ends up filtering the date.

    The usual practice is to create a separate calendar table, then use the date in the calendar for the slicer, and then get the date range in the slicer to calculate the horimetropenultimatroca.

    for example, create the 2 measures below to get the date range in slicer

    selectedRange_start= minx(allselected('calendar'),[date])

    selectedRange_end= maxx(allselected('calendar'),[date])

    then, create a measure to calculate horimetropenultimatroca, for example, you can time offset the obtained date range, use edate() or eomonth()

    FYI: 

    EDATE function (DAX) - DAX | Microsoft Docs

    EOMONTH function (DAX) - DAX | Microsoft Docs

    measure = 
    var _newstart= EDATE([selectedRange_start],-1)
    var _newend= EDATE([selectedRange_end],-1)
    return sumx(filter(all('fact table'),'fact table'[date]>=_newstart && 'fact table'[date]<=_newend), [sale])

    If you need more help, please let me know. 

     

    Best Regards,

    Community Support Team _Tang

    If this post helps, please consider Accept it as the solution to help the other members find it more quickly.