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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
tksnota
Post Patron
Post Patron

Transform Excel Command to DAX or M Language

Hi,

 

I created this command but need help to transform it to Dax or M Language.

 

Thanks...tksnota...

 

(CASE WHEN transtype IN('N','C','P','F')
AND (((gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0) )
OR (gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0))
THEN gbkmut.bdr_hfl ELSE NULL END) AS Debit,

 

(CASE WHEN transtype IN('N','C','P','F')
AND (((gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0) )
OR (gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0))
THEN NULL ELSE -gbkmut.bdr_hfl END) AS Credit,

14 REPLIES 14
_AAndrade
Super User
Super User

Hi @tksnota,

Try this DAX measures:

Debit = 
IF(
    [transtype] IN {"N", "C", "P", "F"} &&
    (
        ([transsubtype] NOT IN {"R", "S"} && [bdr_hfl] >= 0) ||
        ([transsubtype] IN {"R", "S"} && [bdr_hfl] < 0)
    ),
    [bdr_hfl],
    BLANK()
)

Credit = 
IF(
    [transtype] IN {"N", "C", "P", "F"} &&
    (
        ([transsubtype] NOT IN {"R", "S"} && [bdr_hfl] >= 0) ||
        ([transsubtype] IN {"R", "S"} && [bdr_hfl] < 0)
    ),
    BLANK(),
    -[bdr_hfl]
)




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Hi,

 

I want 2 columns created namely Credit and Debit taken from the amount based on the conditions stipulated on transtype and transsubtype 

 

Hope I make myself clear...

 

Thanks...tksnota...

 

tksnota_0-1730217721167.png

 

My last post might solve your issue.
If not please give more details and share how is your table and the disered output.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




I tried your dax but i encountered these problems as shown.

 

I only attempted to use one column for debit...

 

tksnota_0-1730219738422.png

 

Please try this one

CalculatedTable = 
ADDCOLUMNS(
    'OriginalTable', // Replace 'OriginalTable' with the name of your table
    "Debit", 
    IF(
        CONTAINSROW({ "N", "C", "P", "F" }, [transtype]) &&
        (
            (NOT CONTAINSROW({ "R", "S" }, [transsubtype]) && [bdr_hfl] >= 0) ||
            (CONTAINSROW({ "R", "S" }, [transsubtype]) && [bdr_hfl] < 0)
        ),
        [bdr_hfl],
        BLANK()
    ),
    "Credit", 
    IF(
        CONTAINSROW({ "N", "C", "P", "F" }, [transtype]) &&
        (
            (NOT CONTAINSROW({ "R", "S" }, [transsubtype]) && [bdr_hfl] >= 0) ||
            (CONTAINSROW({ "R", "S" }, [transsubtype]) && [bdr_hfl] < 0)
        ),
        BLANK(),
        -[bdr_hfl]
    )
)




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Hi,

 

I have these errors.

 

Thanks...tksnota...

 

tksnota_0-1730289432553.png

 

Hi @tksnota,

Could you share a pbix file with same data so I could take a look?





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




 

Hi,

 

How about we change the Dax wherein any GL Code that starts with "7" and "4" will be extracted to Calculated Column called Debit and anything that starts with "8" will be credit (as shown)?

 

tksnota_0-1730297190147.png

 

@tksnota,

I'm attaching a pbix file with a quick example. See if this could help you.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Hi 

 

Thanks for the pbix.

 

I tried your DAX but my problem is the system won't show the column only the sum as shown from the black box.

 

Anything I need to do so I can get the correct columns?

 

Thanks...tksnota...

 

tksnota_0-1730387478861.png

 

Hi,

What column you're using on your Sum measure? Should be that column, I guess...
I can help you more than this with the information than I have... sorry





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




can i get it for calculated table...thanks...

I don't know if I understood well your question, but try this:

CalculatedTable = 
ADDCOLUMNS(
    'OriginalTable', // The name of your table
    "@Debit", 
    IF(
        [transtype] IN {"N", "C", "P", "F"} &&
        (
            ([transsubtype] NOT IN {"R", "S"} && [bdr_hfl] >= 0) ||
            ([transsubtype] IN {"R", "S"} && [bdr_hfl] < 0)
        ),
        [bdr_hfl],
        BLANK()
    ),
    "@Credit", 
    IF(
        [transtype] IN {"N", "C", "P", "F"} &&
        (
            ([transsubtype] NOT IN {"R", "S"} && [bdr_hfl] >= 0) ||
            ([transsubtype] IN {"R", "S"} && [bdr_hfl] < 0)
        ),
        BLANK(),
        -[bdr_hfl]
    )
)




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Kedar_Pande
Super User
Super User

@tksnota 

Debit = 
SWITCH(
TRUE(),
'gbkmut'[transtype] IN {"N", "C", "P", "F"} &&
(
('gbkmut'[transsubtype] NOT IN {"R", "S"} && 'gbkmut'[bdr_hfl] >= 0) ||
('gbkmut'[transsubtype] IN {"R", "S"} && 'gbkmut'[bdr_hfl] < 0)
),
'gbkmut'[bdr_hfl],
BLANK() // Equivalent to NULL
)
Credit = 
SWITCH(
TRUE(),
'gbkmut'[transtype] IN {"N", "C", "P", "F"} &&
(
('gbkmut'[transsubtype] NOT IN {"R", "S"} && 'gbkmut'[bdr_hfl] >= 0) ||
('gbkmut'[transsubtype] IN {"R", "S"} && 'gbkmut'[bdr_hfl] < 0)
),
BLANK(), // Equivalent to NULL
-'gbkmut'[bdr_hfl]
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.