Forum Discussion

ElvirBotic's avatar
ElvirBotic
Helper III
2 years ago

Fix Measure to work in Matrix table

Hello, I have a measure counting records created for the year. The simple TOTALYTD function in DAX does not produce the correct result so I learned the hard way sometime ago and used Greg Deckler's version to get YTD and I get the correct result in a card visual, but as soon as I add it to a matrix table it is wrong. I remove the ALL function of result variable and then my total count is wrong, but works in the matrix table. Any advice on how to make it work?

TOTALYTD =
    VAR __Date = MAX('POs 2'[DATE CREATED])
    VAR __StartOf = DATE(YEAR(__Date),1,1)
    VAR __DATESYTD = FILTER(SELECTCOLUMNS(ALL('POs 2'),"Date",[DATE CREATED]),[Date] >= __StartOf && [Date] <= __Date)
RETURN
    COUNTX(
        FILTER(ALL
            ('POs 2'),[DATE CREATED] IN __DATESYTD
            ),
            'POs 2'[PO ID]
        )


Without ALL in the return (Wrong total records)



With ALL added in Return (Correct total, wrong values in cells)

 



2 Replies

  • ElvirBotic . Use measures like. Here net is my measure. Always use date table

     

    YTD =
    var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
    var _min = eomonth(_max,-1*MONTH(_max))+1
    return
    CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

    LYTD =
    var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
    var _max = Date(Year(_max1)-1, Month(_max1), Day(_max1))
    var _min = eomonth(_max,-1*MONTH(_max))+1
    return
    CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

     

     

    Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
    https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5bd4
    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

    • ElvirBotic's avatar
      ElvirBotic
      Helper III

      Is net just countrows of table? or is it a countx? 

      net =
      countrows ( POs )
      )