Search code examples
powerbidaxbar-chartslicers

YTD on single bar chart - using Slicer for month selection (PowerBI)


I would like to create a DAX that will make my visual (a single bar chart) display the YTD of a data [see below]

enter image description here

On top of that, I want it to be interactive to a slicer - in a way that i will only select a single month (example: August) & it will show data from Jan-Aug automatically.


Solution

  • With a disconnected date table:

    MyTotalYTD = 
      TOTALYTD(
        SUM('factTable'[Amount]),
        'connectedDateTable'[Date],
        FILTER(
          ALL('connectedDateTable'[Date]),
          'connectedDateTable'[Date] <= MAX('disconnectedDateTable'[Date])
        )
      )
    
    // or
    
    MyTotalYTD = 
      TOTALYTD(
        SUM('factTable'[Amount]),
        'factTable'[Date],
        FILTER(
          ALL('factTable'[Date]),
          'factTable'[Date] <= MAX('disconnectedDateTable'[Date])
        )
      )