To show number in million (M) by using custom format - powerbi

I have to display Value 71,672,885 as 71.6M and I'm using below DAX
IF(Metric[EU]>=1000000,FORMAT(Metric[EU],"#,##0.0,,M")
But its showing value as 71,672,885.0 M. Let me know what I'm missing in above DAX function.
Note: Above function working perfectly in Excel but not in Power BI.

The commas should be before the decimal place.
FORMAT(Metric[EU], "#,##,,.0M")
Here's the function reference:
https://learn.microsoft.com/en-us/dax/custom-numeric-formats-for-the-format-function

Related

Power Bi - Cannot find column in a DAX

I am a newbie in PowerBi and I am trying to create a DAX in order to compare a column with different variables in order to attribute some values in order to do some conditional formatting of the cells.
I read that I must had a MIN(), MAX(), ... in the expression but I just want to compare for each value not with the maximum.
Thanks in advance for your help and your time

Average Duration DAX Power BI

I'm trying to get the mean of a variable typed 'duration' in Power BI, creating a measure like in this formula:
Medida = AVERAGE(Consolidado[TMA])
When I try this it returns a decimal number like '0.003..', but I can't modify this measure to duration/time.
Can someone give me a hint?
The DAX is basically summarizing the result. To overcome this issue add the FORMAT function at the beginning and format it accordingly as you need.
Measure = FORMAT(AVERAGEA('Table'[Date]), "HH:MM:SS")
This should give you the output in the Time Format.

Power BI DAX - Running the MEDIAN or MEDIANX formula for a calculated column gives error message

I have been trying to generate a calculated column within Power BI Desktop using the MEDIAN formula to get the median age. I checked to see if there were any inconsistencies like text data or blank data within the Age column but, did not find any such instances. The error message is as follows -
Expressions that yield variant data-type cannot be used to define
calculated columns.
The data used in the analysis is hosted on data.world
Any help will be highly appreciated.
This is a pretty strange situation but I think I found the explanation on the Microsoft Community Forum.
When the underlying column is of data type Whole Number, MEDIAN function returns a variant data type because it may return a Whole Number when there is no interpolation or a Decimal Number when there is interpolation. While measures can be of variant data type, calculated columns must be of a single data type, hence the error. To force MEDIAN to always return Decimal Number, change the expression to MEDIANX(Table1, [Column2] * 1.0).
Another fix would be to convert the Age column to the decimal number type rather than the whole number type. I also found wrapping with VALUE work.

How to change dataype of calculated column number to text in power BI

I have a power bi report with live connection to the SSAS cube. I have a numeric column which I wanted to convert to text using DAX, since its a live-conection i cannot change this on power bi end. is there a way ?
You can use the format function in dax,
For example you can add a new column as the following example:
New_Column = FORMAT(Table1[NumericColumn];"General Number")
Get this example from the source in Pre-Defined Numeric Formats for the FORMAT Function
Hope this can help you!

Access to fields in IF sentence in DAX in Power BI Desktop

When I use SUM for example the intellisense of the editor shows me the columns of my table but when I use IF or Switch I'm not shown any column.
In this example of If (https://powerbi.microsoft.com/es-es/documentation/powerbi-desktop-tutorial-create-calculated-columns/) the column between [] works fine but when I put my column between [] I have error
error if
Any idea please?
Regards
I can see you are creating a measure while in the tutorial they are creating a calculated column. Measures and Calculated columns behave different, while creating a calculated column the expression you are using takes the context of each row so you can reference any column directly by [Column].
However measures evaluate in different context so they need an aggregation function to determine the value of your columns.
EXAMPLE: Calculated Column.
Is Red Calculated Column = IF([Color]="Red","Yes","No")
EXAMPLE: Measures.
Is Red Measure = IF(FIRSTNONBLANK([Color],0)="Red","Yes","No")
Note I used FIRSTNONBLANK aggregation function to access the [Color] column from a measure.
The above expression could not work for you depending on your measure, I only posted it for example purposes.
I found the answer
TotalHoras = SUMX(Horas;if(Horas[Tipo]="M";Horas[Duration]/60;Horas[Duration]))
Like #alejandrozuleta says Measures need an aggregation function to works