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
Adiotic
New Member

Dynamically find difference between two items from same column and plot a timeseries line chat

I m trying to create a line chart by calculating difference between two selected items from slicer.

 

Suppose dataset like 

Item: {A,B,C,A,C,B}

Date: { 1/2/2024, 1/2/2024,1/2/2024,1/3/2024.....}

Value {1,5,3,7.....}

 

I want to choose say two items A and B and plot their differences on a line chart and also select another pair B and C and do similar action to plot in same chart for comparing both differences 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,@Adiotic .Hello,@danextian Thank you very much for the help of this problem.
I'd like to share some of my thoughts on problem solving.
You want to show a difference between two items in a line chart by selecting several different item options in a slicer.
After understanding your requirement, I have carried out the following test, if your requirement can be achieved by the following method. You can use it as a reference.
If you can provide me with specific data, it will be helpful in solving your problem.
Here is the test data I created based on your description.

vjtianmsft_0-1715332600544.png


You can refer to the following website which describes "How to compare selected categories in power BI without copying tables, slicers".
URL:Comparing Selected Categories in Power BI | by Patrick Pichler | Creative Data | Medium
The specific implementation of the test function is as follows:
After selecting two different items on the slicer, the line graph and table will display different contents and hints respectively.
The line graph shows the difference between the sum of the values of each item between different items.
Implementation steps.
Create a measure to limit the number of slicer filter conditions selected by the user (requires only two items to be selected at a time).

vjtianmsft_1-1715332686516.png

 

Selection = 
 VAR _Count =COUNTROWS(VALUES(table_test[item]))
VAR _Concat = CONCATENATEX(VALUES(table_test[item]),[item],"|")
RETURN IF(_Count>2,"Please select only 2",_Concat)

 

vjtianmsft_2-1715332711548.png

 

Selection1 = IF(
    (PATHITEM([Selection],1)="Please select only
2" ),"Please select 1",PATHITEM([Selection],1))

Selection2 = IF(
    (PATHITEM([Selection],2) =""),
    "Please select 2",PATHITEM([Selection],2))

 

vjtianmsft_3-1715332776606.png

 

TotalValues = CALCULATE(SUM('table_test'[values]),
FILTER(ALLSELECTED(table_test),'table_test'[item]=MAX('table_test'[item])))
Selection1M_ = 
VAR sel = [Selection1]
RETURN CALCULATE([TotalValues],'table_test'[item]=sel)
Selection2M_ = 
VAR sel =[Selection2]
RETURN CALCULATE([TotalValues],'table_test'[item]=sel)

 

Calculate the difference between the two options(calculate column)

 

Two_differ_result = 
[Selection1M_]-[Selection2M_]

 


The final result is shown below:

vjtianmsft_4-1715332894911.png

vjtianmsft_5-1715332913351.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi,@Adiotic .Hello,@danextian Thank you very much for the help of this problem.
I'd like to share some of my thoughts on problem solving.
You want to show a difference between two items in a line chart by selecting several different item options in a slicer.
After understanding your requirement, I have carried out the following test, if your requirement can be achieved by the following method. You can use it as a reference.
If you can provide me with specific data, it will be helpful in solving your problem.
Here is the test data I created based on your description.

vjtianmsft_0-1715332600544.png


You can refer to the following website which describes "How to compare selected categories in power BI without copying tables, slicers".
URL:Comparing Selected Categories in Power BI | by Patrick Pichler | Creative Data | Medium
The specific implementation of the test function is as follows:
After selecting two different items on the slicer, the line graph and table will display different contents and hints respectively.
The line graph shows the difference between the sum of the values of each item between different items.
Implementation steps.
Create a measure to limit the number of slicer filter conditions selected by the user (requires only two items to be selected at a time).

vjtianmsft_1-1715332686516.png

 

Selection = 
 VAR _Count =COUNTROWS(VALUES(table_test[item]))
VAR _Concat = CONCATENATEX(VALUES(table_test[item]),[item],"|")
RETURN IF(_Count>2,"Please select only 2",_Concat)

 

vjtianmsft_2-1715332711548.png

 

Selection1 = IF(
    (PATHITEM([Selection],1)="Please select only
2" ),"Please select 1",PATHITEM([Selection],1))

Selection2 = IF(
    (PATHITEM([Selection],2) =""),
    "Please select 2",PATHITEM([Selection],2))

 

vjtianmsft_3-1715332776606.png

 

TotalValues = CALCULATE(SUM('table_test'[values]),
FILTER(ALLSELECTED(table_test),'table_test'[item]=MAX('table_test'[item])))
Selection1M_ = 
VAR sel = [Selection1]
RETURN CALCULATE([TotalValues],'table_test'[item]=sel)
Selection2M_ = 
VAR sel =[Selection2]
RETURN CALCULATE([TotalValues],'table_test'[item]=sel)

 

Calculate the difference between the two options(calculate column)

 

Two_differ_result = 
[Selection1M_]-[Selection2M_]

 


The final result is shown below:

vjtianmsft_4-1715332894911.png

vjtianmsft_5-1715332913351.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

danextian
Super User
Super User

Hi @Adiotic ,

 

Can you please post a workable sample data and your expected result from that?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors