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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Cross Calculation between two lines after filtering

Hi,

 

I need an help about the following.

I would like to perform some pricing variance comparison on my data, the query I started with is structured with the following columns:

Materialunique identifier for materials sold, may repeat several times as we sold to several customer in the different periods
Yearcan be two values 2022 or 2023
Orders.Sold-To Ptunique identifier for customer, may repeat several times as we sold several materials in the different periods
Billing quantitywhole number
ComparableLabeldefines if a sales is repeated in both years, a sales is an event where to the same customer (Orders.Sold-To Pt) has been sold the same material
Average Priceis Net Value LC BDG / Billing quantity
Concatenateis a concatenation material+Orders.Sold-To Pt
Net Valuel LC BDGis the revenue column

 

I would like to write a measure in dax or via calculated column, that will do the following operations:

step1: filters for those that in the column ComparableLabel has the value "Comparable"

step2: filters for those that has in the column "Concatenate" the same value, the visual table results should be a two liner with two different values in column Year

step3: take the average price in the column Average Price for the same row that has Year=2022

step4: take the billing quantity in the column Billing quantity for the same row that has Year=2023

step5: multiply step3 and step4 results

 

The idea is to evaluate the average price in the previous Year with the Billing quantity of the current one, for two values that after the initial filtering will stay always in a two liner, just not on the same line but always in the "other one".

 

The idea is also to have a total of this new dimension that would be comparable with the current year revenue, so also the sum need to be consistent.

I may miss some information on techniques, so that above is my interpretation - here is a data sample:

MaterialYearOrders.Sold-To PtBilling quantityComparableLabelAverage PriceConcatenateNet Valuel LC BDG
1ABC20235228234Not Comparable5767.591ABC-52282323070.36
2ABC20231022482Comparable156.222ABC-102248312.44
3ABC20221009091Comparable1403ABC-100909140
3ABC202310090910Comparable165.83ABC-1009091658

 

Also steps:

 

Step 1 filter the ComparableLabel

MaterialYearOrders.Sold-To PtBilling quantityComparableLabelAverage PriceConcatenateNet Valuel LC BDG
2ABC20231022482Comparable156.222ABC-102248312.44
3ABC20221009091Comparable8,359.123ABC-100909140
3ABC202310090910Comparable165.83ABC-1009091658

Step 2 filter the same "Concatenate" values

MaterialYearOrders.Sold-To PtBilling quantityComparableLabelAverage PriceConcatenateNet Valuel LC BDG
3ABC20221009091Comparable8,359.123ABC-100909140
3ABC202310090910Comparable165.83ABC-1009091658

 

Step 3 identifiy 2022 Average Price in red

MaterialYearOrders.Sold-To PtBilling quantityComparableLabelAverage PriceConcatenateNet Valuel LC BDG
3ABC20221009091Comparable8,359.123ABC-100909140
3ABC202310090910Comparable165.83ABC-1009091658

 

Step 4 identify 2023 Billing quantitiy in green

 

MaterialYearOrders.Sold-To PtBilling quantityComparableLabelAverage PriceConcatenateNet Valuel LC BDG
3ABC20221009091Comparable8,359.123ABC-100909140
3ABC202310090910Comparable165.83ABC-1009091658

 

 

Step 4 returns 8359.12*10

Hope the sample is helping.

 

Thank you

 

Davide

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create tables.

Comparable = 
    FILTER (
        'Table',
        'Table'[ComparableLabel] = "Comparable"
    )
same Concatenate = FILTER (
    'Comparable',
    CALCULATE (
        COUNTROWS ( 'Comparable' ),
        ALLEXCEPT ( 'Comparable', 'Comparable'[Concatenate] )
    ) > 1
)

(3)We can create measures. 

Result = 
var _2022=CALCULATE(SUM('same Concatenate'[Average Price]),FILTER(ALL('same Concatenate'),'same Concatenate'[Year]=2022 && 'same Concatenate'[Concatenate]=MAX('same Concatenate'[Concatenate])))
var _2023=CALCULATE(SUM('same Concatenate'[Billing quantity]),FILTER(ALL('same Concatenate'),'same Concatenate'[Year]=2023 && 'same Concatenate'[Concatenate]=MAX('same Concatenate'[Concatenate])))
return _2022*_2023
color1 = IF(
MAX('same Concatenate'[Year])=2022,"red")
color2 = IF(
MAX('same Concatenate'[Year])=2023,"green")

(3) Setting the Conditional Format and then the result is as follows.

vtangjiemsft_0-1690266160219.pngvtangjiemsft_1-1690266176357.pngvtangjiemsft_2-1690266187789.png

 

 

 

Best Regards,

Neeko Tang

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
v-tangjie-msft
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create tables.

Comparable = 
    FILTER (
        'Table',
        'Table'[ComparableLabel] = "Comparable"
    )
same Concatenate = FILTER (
    'Comparable',
    CALCULATE (
        COUNTROWS ( 'Comparable' ),
        ALLEXCEPT ( 'Comparable', 'Comparable'[Concatenate] )
    ) > 1
)

(3)We can create measures. 

Result = 
var _2022=CALCULATE(SUM('same Concatenate'[Average Price]),FILTER(ALL('same Concatenate'),'same Concatenate'[Year]=2022 && 'same Concatenate'[Concatenate]=MAX('same Concatenate'[Concatenate])))
var _2023=CALCULATE(SUM('same Concatenate'[Billing quantity]),FILTER(ALL('same Concatenate'),'same Concatenate'[Year]=2023 && 'same Concatenate'[Concatenate]=MAX('same Concatenate'[Concatenate])))
return _2022*_2023
color1 = IF(
MAX('same Concatenate'[Year])=2022,"red")
color2 = IF(
MAX('same Concatenate'[Year])=2023,"green")

(3) Setting the Conditional Format and then the result is as follows.

vtangjiemsft_0-1690266160219.pngvtangjiemsft_1-1690266176357.pngvtangjiemsft_2-1690266187789.png

 

 

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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