Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Calculate date filter

Hello, 

 

I ve been trying to improve my calculation with additional date filter, but it doesnt make any diff. It behaves like it calculates the result for all dates

 

Everything is calculates in one table. measure reacts correctly to date slicer or filter visual modification, but only not for dax...

 

Aby idea what can be wrong?

 

  • tamerj1's avatar
    tamerj1
    3 years ago

    Anonymous 
    Please try

    Yield Mech. assemblyprevmonth =
    VAR CurrentYearMonth =
        MAX ( 'Date'[Year Month Number] )
    VAR MechAssembly =
        CALCULATETABLE (
            TJob,
            TJob[SekundærNavn] = "Mech. assembly",
            'Date'[Year Month Number] = CurrentYearMonth - 1,
            ALL ( 'Date' )
        )
    RETURN
        ROUND (
            DIVIDE (
                SUMX ( MechAssembly, TJob[FirstPassQty] ),
                SUMX ( MechAssembly, TJob[Antal] )
            ),
            4
        )

17 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Anonymous 

    bring CALCULATE at line number 2 instead of 5

    • Anonymous's avatar
      Anonymous
      Not applicable

      Could you elaborate more? You mean putting sumx as VAR?

       

      Yield Mech. assembly =
      VAR nom =
          CALCULATE( SUMX(TJob, TJob[Antal]), TJob[SekundærNavn] = "Mech. assembly" , PREVIOUSMONTH(TJob[Dato]))
      VAR den =
          CALCULATE(SUMX(TJob, TJob[FirstPassQty]), TJob[SekundærNavn] = "Mech. assembly", PREVIOUSMONTH(TJob[Dato]))
      RETURN
          ROUND(
              DIVIDE (
                  den,
                   nom),
                  4)

       

      • tamerj1's avatar
        tamerj1
        Community Champion

        Anonymous 

        Please try

        Yield Mech. assembly111 =
        CALCULATE (
        VAR MechAssembly =
        FILTER ( TJob, TJob[SekundarNavn] = "Mech. assembly" )
        RETURN
        ROUND (
        DIVIDE (
        SUMX ( MechAssembly, TJob[Antal] ),
        SUMX ( MechAssembly, TJob[FirstPassQty] )
        ),
        4
        ),
        PREVIOUSMONTH ( TJob[Dato] )
        )

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Please try this measure:

     

    (Try PARALLELPERIOD(TJob[Dato],-1,MONTH) instead of PREVIOUSMONTH(TJob[Dato]))

     

    PrevMonth = 
    CALCULATE(SUMX(Sales, Sales[Unit Cost]), PARALLELPERIOD('Date'[Date],-1,MONTH))

     

     

    Then the result is as follows.

    Best Regards,

    Neeko Tang

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