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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

New column to get complementary row data if multiple criteria is met

Hi,

I want to create a new column within the same table based in 3 criterias&columns that must be met:
-Same Code
-Same Month
-Same Prov.
If they are equal, then the new column will contain the missing data between another 2 columns: Amount and Fact.

Example Table:

CodeMonthProv.AmountFact.
474588221A10000
474588221A05
474522661B50000
1234562C2000
1234562C01


We add the new column and get:

CodeMonthProv.AmountFact.NewColumn
474588221A100005
474588221A051000
474522661B500000
1234562C20001
1234562C01200


Thanks!!

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@Anonymous  try this as a new column

 

X = 
IF (
    [Fact.] = 0
        && CALCULATE (
            MAX ( tx[Fact.] ),
            ALLEXCEPT ( tx, tx[Code], tx[Month], tx[Prov.] )
        ) <> 0,
    CALCULATE (
        MAX ( tx[Fact.] ),
        ALLEXCEPT ( tx, tx[Code], tx[Month], tx[Prov.] )
    ),
    IF (
        [Amount] = 0
            && CALCULATE (
                MAX ( tx[Fact.] ),
                ALLEXCEPT ( tx, tx[Code], tx[Month], tx[Prov.] )
            ) <> 0,
        CALCULATE (
            MAX ( tx[Amount] ),
            ALLEXCEPT ( tx, tx[Code], tx[Month], tx[Prov.] )
        )
    )
)

 

breakdown with three 3 calculated columns

_maxfact = CALCULATE(MAX(tx[Fact.]),ALLEXCEPT(tx,tx[Code],tx[Month],tx[Prov.]))

_maxamt = CALCULATE(MAX(tx[Amount]),ALLEXCEPT(tx,tx[Code],tx[Month],tx[Prov.]))

New Column = Column = IF([Fact.]=0&&[_maxfact]<>0,[_maxfact], IF([Amount]=0&&[_maxfact]<>0,[_maxamt]))

 

Capture.PNG

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

2 REPLIES 2
smpa01
Super User
Super User

@Anonymous  try this as a new column

 

X = 
IF (
    [Fact.] = 0
        && CALCULATE (
            MAX ( tx[Fact.] ),
            ALLEXCEPT ( tx, tx[Code], tx[Month], tx[Prov.] )
        ) <> 0,
    CALCULATE (
        MAX ( tx[Fact.] ),
        ALLEXCEPT ( tx, tx[Code], tx[Month], tx[Prov.] )
    ),
    IF (
        [Amount] = 0
            && CALCULATE (
                MAX ( tx[Fact.] ),
                ALLEXCEPT ( tx, tx[Code], tx[Month], tx[Prov.] )
            ) <> 0,
        CALCULATE (
            MAX ( tx[Amount] ),
            ALLEXCEPT ( tx, tx[Code], tx[Month], tx[Prov.] )
        )
    )
)

 

breakdown with three 3 calculated columns

_maxfact = CALCULATE(MAX(tx[Fact.]),ALLEXCEPT(tx,tx[Code],tx[Month],tx[Prov.]))

_maxamt = CALCULATE(MAX(tx[Amount]),ALLEXCEPT(tx,tx[Code],tx[Month],tx[Prov.]))

New Column = Column = IF([Fact.]=0&&[_maxfact]<>0,[_maxfact], IF([Amount]=0&&[_maxfact]<>0,[_maxamt]))

 

Capture.PNG

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Amazing answer!!

Thanks a lot!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.