Search code examples
chartspowerbidax

Power bi: Restrict data in a chart using dax


I have a chart where in X-axis, its the day of the quarter, in y-axis is the amount. in legend is the year and Quarter. This is the backlog data for that reason it have the future data too. In the X-axis, The days will be constant i.e., 92 (Maximum number of days in a quarter) Today is Jan 8th,2024, 8th day of the quarter, so the data needs to be showed until 8(the chart should not show any data from 9 to 92. similar to QTD) even when 9 or 10 have the data. How to restrict this using a dax formula?


Solution

  • You haven't shared any info on your data model set-up and what you are using for the Y-axis. The following may work for you:

    Chart Y-axis value = 
      TOTALQTD(
        SUM('table'[something]),
        'YourDateTable'[Date],
        'YourDateTable'[Date] <= TODAY()
      )
    

    Or alternatively:

    Chart Y-axis value = 
      var todayQtrDay = DATEDIFF(DATE(YEAR(TODAY()), (QUARTER(TODAY()) - 1) * 3 + 1, 1), TODAY(), DAY) + 1
      var chartX = SELECTEDVALUE('Same as your X-axis'[Day])
      var result = <your calculation>
      return IF(chartX <= todayQtrDay, result)