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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
John_Silva642
Frequent Visitor

FORMAT result according with filter and put It in a bar chart

Hi,

I'm trying to create a code that FORMAT the result according to the selected filter.

My code works on cards, but It doesn't work on the bar charts.

Can someone help me, please?

Below there is the DAX code and a data model example.

 

 

PERFORMED_BY_TOTAL_TWELVEMONTHS =
VAR _LASTREF =
CALCULATE(
MAX('DBN'[Data]),
'DBN'[Tipo] = "PERFORMED/TOTAL",
'DBN'[Valor] <> BLANK()
)
VAR _ELEVENMONTHSAGO =
EDATE(_LASTREF,-11)
VAR _INDICATOR =
CALCULATE(
SELECTEDVALUE('DBN'[KPI], "ERROR"),
'DBN'[Tipo] = "PERFORMED/TOTAL"
)
VAR _RESULT =
CALCULATE(
SUM('DBN'[Valor]),
'DBN'[Tipo] = "PERFORMED/TOTAL",
'DBN'[Data] >= _ELEVENMONTHSAGO
&& 'DBN'[Data] <= _LASTREF
)
VAR _FORMAT =
IF(
_INDICATOR = "% Valor pendente",
FORMAT(_RESULT, "0.000%"),
IF(
_INDICATOR = "Quantidade Propostas Eletrônicas Total",
FORMAT(_RESULT, "Standard"),
FORMAT(_RESULT, "Percent")
)
)
RETURN
_FORMAT

 

 

John_Silva642_0-1671743391427.png

John_Silva642_1-1671743781008.png

Just _RESULT

John_Silva642_2-1671744324328.png

 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @John_Silva642 ,

 

Have you ever considered about using field parameter?

Field parameters allow users to dynamically change the measures or dimensions being analyzed within a report. This feature can help your report readers explore and customize the analysis of the report by selecting the different measures or dimensions they're interested in.

For example:

vjianbolimsft_0-1672209363671.png

Then apply to the visual:

vjianbolimsft_2-1672209433577.png

vjianbolimsft_3-1672209450705.png

For more details, please refer to:

Let report readers use field parameters to change visuals (preview) - Power BI | Microsoft Learn

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @John_Silva642 ,

 

Have you ever considered about using field parameter?

Field parameters allow users to dynamically change the measures or dimensions being analyzed within a report. This feature can help your report readers explore and customize the analysis of the report by selecting the different measures or dimensions they're interested in.

For example:

vjianbolimsft_0-1672209363671.png

Then apply to the visual:

vjianbolimsft_2-1672209433577.png

vjianbolimsft_3-1672209450705.png

For more details, please refer to:

Let report readers use field parameters to change visuals (preview) - Power BI | Microsoft Learn

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It solved my problem. Thank you!

v-jianboli-msft
Community Support
Community Support

Hi @John_Silva642 ,

 

You can't use the Format function in your bar chart because it will convert the values to text format, making it unrecognizable to visual.

For more details, refer to:

FORMAT function (DAX) - DAX | Microsoft Learn

You can change the format of your measure here:

vjianbolimsft_0-1671758206855.png

Output:

vjianbolimsft_1-1671758223776.png

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @v-jianboli-msft

But I need something like the FORMAT function to change the result according to the filter.

Example:

John_Silva642_0-1671807806409.png

Percent FORMAT (Standard)

John_Silva642_1-1671807847089.png

Percent FORMAT (0.000%)

John_Silva642_2-1671807891242.png

Percent FORMAT (Percent)




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.