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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Niels_T
Post Patron
Post Patron

How to use SWITCH function

Hello,


I have appended both my credit memo and invoice tables.

 

Now I would like to make an extra column that contains the Document Type which is either credit memo or invoice.

 

I tried doing this with a switch function that goes as followed:

 

Document Type =
SWITCH (
TRUE(),
CONTAINS('$Sales + Cr_Memo Header', '$Sales + Cr_Memo Header'[Posting Description], "Invoice"), "Invoice",
CONTAINS('$Sales + Cr_Memo Header', '$Sales + Cr_Memo Header'[Posting Description], "Credit memo"), "Credit Memo"
)
 
I used the column posting description. This column gives me all the invoice and credit memo values with a number behind it.
 
The logic of the function that I wanted to write is as followed:
 
IF the column post description contains the value invoice then add invoice in the document type column. IF it contains Credit Memo then add Credit Memo in the document type column.
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

A simpler way to do this would be in the query editor.  Before you append the tables, add a Custom Column with a constant string value in each table called "Document Type" with = "Invoice" or = "Credit Memo".

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

A simpler way to do this would be in the query editor.  Before you append the tables, add a Custom Column with a constant string value in each table called "Document Type" with = "Invoice" or = "Credit Memo".

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Apparently you don't need to do this before you append  them. I added custom columns and my appended table automatically updated itself.

 

Thanks for the help!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.