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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

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 @Anonymous,

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!




Anonymous
Not applicable

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!




Anonymous
Not applicable

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!




Anonymous
Not applicable

Hi,

 

I have these errors.

 

Thanks...tksnota...

 

tksnota_0-1730289432553.png

 

Hi @Anonymous,

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!




Anonymous
Not applicable

 

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

 

@Anonymous,

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!




Anonymous
Not applicable

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!




Anonymous
Not applicable

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

@Anonymous 

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.