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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
FatemaRangwala
New Member

Format dax produces blanks

Hi PowerBI Community,

 

I am facing an issue with the FORMAT DAX function.

I have a few measures that divide and produce the output in % form and I am using this output in the SWITCH DAX if account code = a then this if account code = b then this and if I use this switch measure as general FORMAT it will return correct output without blanks i.e.,

 

SWITCH(
MAX( 'TableName'[account code] ),
"account_code",  [measurename],
"account_code", [measurename],
)

 

but if we use FORMAT to convert it to % it returns the output with blanks:

SWITCH(
MAX( 'TableName'[account code] ),
"account_code", FORMAT( [measurename], "#0.00%" ),
"account_code", [measurename],
)

 

Anyone has any idea how to avoid blanks while using FORMAT but not modifying the DAX or not using blank function to avoid it as the dataset is quite huge so it is degrading the performance and also we cannot convert the whole measure as % as we have net sales in that.

 

Your response will be appreciated.

 

Thank You in advance!

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @FatemaRangwala ,

 

If the referenced measure returns blank, I dont see any other reason for FORMAT to return as such. You can add + 0  or -0 after the referenced measure in your formula so it shows zero when blank.

=
SWITCH (
    MAX ( 'TableName'[account code] ),
    "account_code", FORMAT ( [measurename] + 0, "#0.00%" ),
    "account_code", [measurename]
)

Alternatively, look into dynamic format strings so your measure still returns a number but formatted instead of text if FORMAT  is used.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4
Alex87
Super User
Super User

can you provide a sample data that reproduces your issue?




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!




danextian
Super User
Super User

Hi @FatemaRangwala ,

 

If the referenced measure returns blank, I dont see any other reason for FORMAT to return as such. You can add + 0  or -0 after the referenced measure in your formula so it shows zero when blank.

=
SWITCH (
    MAX ( 'TableName'[account code] ),
    "account_code", FORMAT ( [measurename] + 0, "#0.00%" ),
    "account_code", [measurename]
)

Alternatively, look into dynamic format strings so your measure still returns a number but formatted instead of text if FORMAT  is used.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Alex87
Super User
Super User

Hello,

True using this:

VAR _Condition = MAX('TableName'[account code])
VAR _Result = 
SWITCH(
    TRUE(),
   _Condition  = "account_code", FORMAT([measurename], "#0.00%"),
   _Condition = "another_code", FORMAT([measurename], "#0.00"),
 
    FORMAT([measurename], "#0.00%")
)
RETURN _Result

 

If it helps, please mark my reply as the solution. Thanks




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!




Hi @Alex87 ,

 

But this solution is not working.

 

Thanks

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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