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
Joanne
Frequent Visitor

Replace/Substitute value for text in specific column using DAX

Hi, 

Can you please help in creating a measure using DAX to fulfil the 4 conditions below? Also the total amount should be summing up the rows after the conditions are applied.

 

1. If Company, Cost Center & Posting Period for Doc Type "PY" is the same as "PD", take "PD" amount

2. In the absence of "PD" for the same Company,  Cost Center & Posting Period, take "PY" amount 

3. In the absence of "PY" for the same Company, Cost Center & Posting Period, do not take "PD" amount 

4. The rest of the Doc Type i.e. AP or JE should remained unchanged

 

Sample data:

Fact Table

CompanyCost CenterPosting PeriodDoc Type Amount 
502222222Apr-21PY         (30,000.00)
502222222Apr-21PD         (30,000.00)
601111111Apr-21PY         (16,000.00)
601111111Apr-21PD         (16,000.00)
502222222Apr-21JE         (12,000.00)
502222222May-21PD         (15,000.00)
601111111May-21PD           (8,000.00)
601111111May-21JE         (14,000.00)
502222222May-21AP         (10,000.00)
502222222Jun-21PY         (24,000.00)
          (175,000.00)

 

Result:

CompanyCost CenterPosting PeriodDoc Type Amount 
502222222Apr-21PD         (30,000.00)
601111111Apr-21PD         (16,000.00)
502222222Apr-21JE         (12,000.00)
601111111May-21JE         (14,000.00)
502222222May-21AP         (10,000.00)
502222222Jun-21PY         (24,000.00)
          (106,000.00)

 

I appreciate any help. Thanks!

1 REPLY 1
Greg_Deckler
Super User
Super User

@Joanne Try this, PBIX is attached below signature. You want Table28 and Page 6.

Measure 3 = 
    VAR __PY = MAXX(FILTER('Table28',[Doc Type]="PY"),[ Amount ])
    VAR __PD = MAXX(FILTER('table28',[Doc Type]="PD"),[ Amount ])
RETURN
    SWITCH(TRUE(),
        NOT(ISBLANK(__PD)) && NOT(ISBLANK(__PY)),__PD,
        NOT(ISBLANK(__PY)) && ISBLANK(__PD),__PY,
        NOT(ISBLANK(__PD)) && ISBLANK(__PY),BLANK(),
        MAX('Table28'[ Amount ])
    )


Measure 3 Total = 
    VAR __Table = SUMMARIZE('Table28',[Company],[Cost Center],[Posting Period],[Doc Type],"__Measure",[Measure 3])
RETURN
    IF(HASONEVALUE('Table28'[Company]),[Measure 3],SUMX(__Table,[__Measure]))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors