Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
DataOK
Frequent Visitor

Add slicer option as dynamic filter to line graph

Hello,

 

I want to have a line graph based on a slicer selection.

 

My data looks like this: (this is already a table created as measure for some other reports)

 

ServicenameAvailabilityDateDepartment
Service 1100%01.01.2025Group A
Service 2100%01.01.2025Group B
Service 3100%01.01.2025Group C
Service 499,99%01.01.2025Group B
Service 598,99%01.01.2025Group A
Service 198,99%01.02.2025Group A
Service 299,99%01.02.2025Group B
Service 395,99%01.02.2025Group C
Service 4100%01.02.2025Group B
Service 5100%01.02.2025Group A
Service 197,99%01.03.2025Group A
Service 296,99%01.03.2025Group B
Service 398,99%01.03.2025Group C
Service 499,55%01.03.2025Group B
Service 597,77%01.03.2025Group A

 

The User selects one of the Groups (A, B or C) via slicer and on the page there are a couple of line graphs that should display the corresponding services.  For Group A in this case Service 1 and 5 in two different line charts. In the line chart there should be shown the data for every month of the current year and the last year. (this is done via the filter option for the visual). But with this filter option (in advanced filter) I can only filter for Servicename and add two options e.g. one for Group A and Group B but not for Group C as third option.

 

DataOK_1-1753707650510.png


I also tried to create a measure for this and add this as filter to the line chart (or table to check the values). It shows the correct values within a table (with option do not summarize) but did not work for line chart.

 

Graph3 = 
IF ( 
    "Group A" in VALUES(Dyn_Table_Availability[Department]), 
    CALCULATE(DISTINCT(Dyn_Table_Availability[Availability]), Dyn_Table_Availability[Servicename]="Service 1"), 
    IF (
          "Group B" in VALUES(Dyn_Table_Availability[Department]),
          CALCULATE(DISTINCT(Dyn_Table_Availability[Availability]), Dyn_Table_Availability[Servicename]="Service 2"),
          IF (
            "Group C" in VALUES(Dyn_Table_Availability[Department]),
            CALCULATE(DISTINCT(Dyn_Table_Availability[Availability]), Dyn_Table_Availability[Servicename]="Service 3"),
            BLANK())
        )
    )

 

 

DataOK_2-1753707679778.png

DataOK_3-1753707691056.png

 


Any idea? Thx for any help. 

1 ACCEPTED SOLUTION

Hi @DataOK,

Please refer the attached pbix file for your issue:

vsaisraomsft_0-1753868188051.png

Hope this helps

Thank you.

View solution in original post

6 REPLIES 6
burakkaragoz
Community Champion
Community Champion

Hi @DataOK ,

Your DAX is way too complicated for what you're trying to do. You're fighting against Power BI instead of letting it work naturally.

The real issue: You're using DISTINCT() which returns a table, but line charts need single values. That's why it works in a table but not in your line chart.

Easiest fix - ditch the complex measure: Just put Department in a slicer, then create your line charts with:

  • X-axis: Date
  • Values: Availability
  • Legend: Servicename

When someone picks "Group A", they'll automatically see Service 1 and Service 5 lines. No fancy DAX needed.

If you really want separate charts for each service:

Service 1 Chart = 
CALCULATE(
    AVERAGE(Dyn_Table_Availability[Availability]),
    Dyn_Table_Availability[Servicename] = "Service 1"
)

Make one measure per service, then separate line charts.

Your nested IF approach is a nightmare to maintain. What happens when you add Group D? More nested IFs?

Better dynamic approach:

Dynamic Service = 
VAR SelectedGroup = SELECTEDVALUE(Dyn_Table_Availability[Department])
VAR ServiceName = 
    SWITCH(SelectedGroup,
        "Group A", "Service 1",
        "Group B", "Service 2", 
        "Group C", "Service 3"
    )
RETURN
CALCULATE(
    AVERAGE(Dyn_Table_Availability[Availability]),
    Dyn_Table_Availability[Servicename] = ServiceName
)

Much cleaner and you can easily add more groups later.

The slicer + natural filtering is probably what you actually want though.


If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
This response was assisted by AI for translation and formatting purposes.

Hey @burakkaragoz ,

 

thanks for the quick response. 

 

Yes sure your solutions looks much easier to maintein for the future. 

 

It also looks fine for me. But it do not show the correct figures! It seems that the average is not the original number! Example result from my date with your dax above. From my point of view this is due to the used AVERAGE command.

 

MonthAvailabilityshown average with your dax
January100,0099,99
February99,9999,99
March100,0099,99
April100,0099,01
May99,7899,70
June99,9797,62

@DataOK ,

Ah, you're absolutely right! AVERAGE is messing up your numbers because it's averaging across multiple rows when there might be multiple records per month.

The problem: If you have multiple services or multiple records for the same month, AVERAGE calculates the mean of all those values, not the actual availability figure you want.

Try this instead:

Service 1 Chart = 
CALCULATE(
    MAX(Dyn_Table_Availability[Availability]),
    Dyn_Table_Availability[Servicename] = "Service 1"
)

Or if you know there should only be one value per month:

Service 1 Chart = 
CALCULATE(
    VALUES(Dyn_Table_Availability[Availability]),
    Dyn_Table_Availability[Servicename] = "Service 1"
)

Better approach - check your data structure first: Can you confirm how many rows you have per month for each service? If there are multiple rows, that explains why AVERAGE is giving you different numbers.

Alternative if you have multiple records per month:

 
 
Service 1 Chart = CALCULATE(
    LASTNONBLANK(Dyn_Table_Availability[Availability], 1),
    Dyn_Table_Availability[Servicename] = "Service 1"
)

This takes the last value for each month instead of averaging.

What does your raw data look like - one row per service per month, or multiple rows?

Unfortunately I could not manage to get it working.

 

I have added a demo file with some sample data and charts. But I´m not allowed to upload a file here. 

So I added again my sample data which I use for this. 

 

ServicenameAvailabilityDATEDepartment
Service 110001.01.2025Group 1
Service 19001.02.2025Group 1
Service 18001.03.2025Group 1
Service 17001.04.2025Group 1
Service 16001.05.2025Group 1
Service 15001.06.2025Group 1
Service 29501.01.2025Group 2
Service 28501.02.2025Group 2
Service 27501.03.2025Group 2
Service 26501.04.2025Group 2
Service 25501.05.2025Group 2
Service 24501.06.2025Group 2
Service 39901.01.2025Group 3
Service 38801.02.2025Group 3
Service 37701.03.2025Group 3
Service 36601.04.2025Group 3
Service 35501.05.2025Group 3
Service 34401.06.2025Group 3
Service 44001.01.2025Group 1
Service 45001.02.2025Group 1
Service 46001.03.2025Group 1
Service 47001.04.2025Group 1
Service 48001.05.2025Group 1
Service 49001.06.2025Group 1
Service 57001.01.2025Group 2
Service 56001.02.2025Group 2
Service 55001.03.2025Group 2
Service 54001.04.2025Group 2
Service 53001.05.2025Group 2
Service 52001.06.2025Group 2
Service 66601.01.2025Group 3
Service 67701.02.2025Group 3
Service 68801.03.2025Group 3
Service 69901.04.2025Group 3
Service 610001.05.2025Group 3
Service 610001.06.2025Group 3
Service 710001.01.2025Group 1
Service 710001.02.2025Group 1
Service 710001.03.2025Group 1
Service 78001.04.2025Group 1
Service 78001.05.2025Group 1
Service 78001.06.2025Group 1

 

-----
edit -  what I have seen is that it seems the filter is for the service is not working as excpeted as all services are shown:

DataOK_0-1753784872134.png

 

 

Hi @DataOK,

Please refer the attached pbix file for your issue:

vsaisraomsft_0-1753868188051.png

Hope this helps

Thank you.

Hey @v-saisrao-msft 

 

thanks for the pbix. That really looks good for my solution. I slightly changed a bit the line graph and it works fine for me.

 

DataOK_0-1753881736377.png

 

1 & 2.  I changed the "Servicename" filter to the one from Table "ServiceDepartmentMap" so that the used filter for the group is working (it than shows only the services that are relevant for this group and only 1 value (instead of 24)). Also I selected the service that is valid for this specific line graph. In the chart (in 6) the other service for group a is shown (I also added this to the titel so that it is automaticly switched witht the group). 

3. Group filter is than valid selection for the line graphs and they are switched by selecting the groups

4. I changed the values for x / y axle and legend to have the time graph for every year in the line graph

5. in the line graph now the correct single value is displayed for every single data point (no more average over many service / mixing up the values)

6. service name is also dynamic based on selection per line graph. 

 

Perfect solution! Thank you all very much for your help!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.