Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
Solved! Go to Solution.
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.
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).
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)
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))
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:
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.
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.
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).
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)
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))
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:
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.
Hi @Adiotic ,
Can you please post a workable sample data and your expected result from that?