Forum Discussion

Scrambalot's avatar
Scrambalot
Frequent Visitor
2 years ago
Solved

Using accumulated average as a filter for distinctcount

Hi, Im having a problem. I have a table with users and how many % they have been missing from work and I'm trying to filter if they are below a certain threshold for the period chosen for example 0,...
  • 123abc's avatar
    123abc
    2 years ago

    Create a Date Table: Ensure that you have a date table in your Power BI model. If you don't have one, you can create one by going to "Modeling" and selecting "New Table." Use a formula like the following to create a date table:

     

    DateTable = CALENDAR(MIN('YourData'[Date]), MAX('YourData'[Date]))

     

    1. Create a Slicer: Create a slicer in your report that allows users to select the months they are interested in.

    2. Create a Measure for Selected Period: Create a measure that dynamically calculates the average based on the selected months. Assuming your data has a numeric column called 'Value' that you want to average, and your date table is 'DateTable', the measure could look like this:

    AverageSelectedPeriod =
    CALCULATE(
    AVERAGE('YourData'[Value]),
    FILTER(
    ALL('DateTable'),
    'DateTable'[Date] >= MIN('DateTable'[Date]) && 'DateTable'[Date] <= MAX('DateTable'[Date])
    )
    )

     

    1. This measure uses the CALCULATE function to change the context of the data being evaluated. The FILTER function is used to dynamically filter the data based on the selected date range.

    2. Display the Measure: Now, you can use this measure in your report. When users select a different period using the slicer, the average will be dynamically calculated based on their selection.

    Remember to replace 'YourData' and 'Value' with your actual data table and column names.

    This approach allows you to dynamically calculate the average based on the selected months using a measure, giving you the flexibility to adjust the date range as needed.