I am new to Power BI.
I am working on a task where I need to find the difference between two rows. There are multiple columns.
For a selected date,
Date Attribute Class1 Class2 Class3 Total
30/06/2021 T1 20 30 40 90
30/06/2021 T2 10 15 60 85
01/07/2021 T1 40 30 40 110
01/07/2021 T2 50 40 30 120
I want to find a way to get a T3 (is T2-T1 on a selected day) as below
Expected Output:
30/06/2021 T3 -10 -15 -20 -5
01/07/2021 T3 10 10 -10 10
Please help
Your expected output can be achieved by create a new table as summary:
First, obtain unique data from the table by create new table:
Table = DISTINCT(Sheet1[Date])
Second, create a new column by typing "T3":
Name = "T3"
The new table with basic data before calculation:
Next, calculate the difference between T1 and T2 on class1:
Class1 = CALCULATE(SUM(Sheet1[Class1]),
FILTER(Sheet1,Sheet1[Date]=EARLIER('Table'[Date])),Sheet1[Attribute]="T2") -
CALCULATE(SUM(Sheet1[Class1]),
FILTER(Sheet1,Sheet1[Date]=EARLIER('Table'[Date])),Sheet1[Attribute]="T1")
To calculate the difference for class is using the same formula as above:
Class2 = CALCULATE(SUM(Sheet1[Class2]),
FILTER(Sheet1,Sheet1[Date]=EARLIER('Table'[Date])),Sheet1[Attribute]="T2") -
CALCULATE(SUM(Sheet1[Class2]),
FILTER(Sheet1,Sheet1[Date]=EARLIER('Table'[Date])),Sheet1[Attribute]="T1")
Here is the final output, you can calculate the rest difference as above:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.