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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Solution Supplier
Solution Supplier

can you provide a sample data that reproduces your issue?

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
Solution Supplier
Solution Supplier

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

Hi @Alex87 ,

 

But this solution is not working.

 

Thanks

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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