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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
dantyson80
Frequent Visitor

Convert column into measure

I have a ZIP code column that needs cleaned up to use for a map visual. Some of the zip codes are Canadian (start with letters) and the rest are USA. Some of the US-based ZIP codes are missing leading zeros. I mention the combined US and Canadian zip codes because some options to add leading zeros seem to be based on integers. I found a DAX formula that will allow me to add the leading zeros, but I figured out that the ZIP code has to be a measure (not a column) for it to work. Here is the formula:

RealZipCode = 
SWITCH(
    TRUE(),
    LEN('Table'[ZipCode]) = 5, 'Table'[ZipCode],
    LEN('Table'[ZipCode]) = 4, "0" & 'Table'[ZipCode],
    LEN('Table'[ZipCode]) = 3, "00" & 'Table'[ZipCode]
)

The only options that show up are measures. It seems that there is no easy way to convert a column to a measure, which if it's true, seems very strange. Please help. Thank you.

1 ACCEPTED SOLUTION
dantyson80
Frequent Visitor

I eventually figured out a solution, which is a bit of a workaround unfortunately. In Power Query, I first created a Custom Column that shows me number of characters in the ZIP column:

dantyson80_0-1661780532672.png

Then I was able to create a query that adds the leading zero if the length was less than 5:

dantyson80_1-1661780626384.png

 

View solution in original post

6 REPLIES 6
dantyson80
Frequent Visitor

I eventually figured out a solution, which is a bit of a workaround unfortunately. In Power Query, I first created a Custom Column that shows me number of characters in the ZIP column:

dantyson80_0-1661780532672.png

Then I was able to create a query that adds the leading zero if the length was less than 5:

dantyson80_1-1661780626384.png

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your desired outcome of the visualization looks like, but please try the below whether it suits your requirement.

 

RealZipCode =
SWITCH (
    TRUE (),
    LEN ( SELECTEDVALUE ( 'Table'[ZipCode] ) ) = 5, SELECTEDVALUE ( 'Table'[ZipCode] ),
    LEN ( SELECTEDVALUE ( 'Table'[ZipCode] ) ) = 4, "0" & SELECTEDVALUE ( 'Table'[ZipCode] ),
    LEN ( SELECTEDVALUE ( 'Table'[ZipCode] ) ) = 3, "00" & SELECTEDVALUE ( 'Table'[ZipCode] )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hello Jihwan,

I tried this and it doesn't work. I was able to enter the formula without problems but when I check the RealZipCode measure, it doesn't populate the map at all. Any ideas why this is the case? Thanks.

Hi,

I am not 100% sure without seeing your pbix file, but please try to check data type and category type of your column.

I suggest searching "power bi column category type zip code" in Edge or Google.

Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

The Data category is "Postal code" for ZipCode. I don't think I can send the file due to a large amount of sensitive information. Are there additional screenshots that might help?

Can anyone provide further assistance? I'm still amazed how seemingly difficult it is to get DAX to recognize a column as a measure. Unbelievable.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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