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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
LarsAustin
Helper I
Helper I

Format Extracted List To Show as Currency (Or Two Decimal Number)

Hi,

 

How can i format the list that i extracted through List.Select to a currency format? See below M code and output.

 

LarsAustin_0-1645255386141.png

 

LarsAustin_1-1645255445599.png

 

My desired result is for each of the value in row under column Cost Per Unit to be formatted as Currency or Fixed Decimal.  Like:

 

Cost Per Unit
1.31; 0.50; 0.45; 0.46

 

Thank you

 

Jojemar

 

 

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

If you want to have your list contain values with trailing decimals, as you show, you will need to convert the Number to a text string.

One way to do that is with List.Transform...Number.ToText which will both round the number and show it with two decimals.

 

List.Transform(decimalList, each Number.ToText(_,"0.00"))

 

Original

ronrsnfld_0-1645325061904.png

 

Results

ronrsnfld_1-1645325094542.png

 

 

View solution in original post

10 REPLIES 10
ronrsnfld
Super User
Super User

If you want to have your list contain values with trailing decimals, as you show, you will need to convert the Number to a text string.

One way to do that is with List.Transform...Number.ToText which will both round the number and show it with two decimals.

 

List.Transform(decimalList, each Number.ToText(_,"0.00"))

 

Original

ronrsnfld_0-1645325061904.png

 

Results

ronrsnfld_1-1645325094542.png

 

 

Exactly what I need.

 

Thanks so much @ronrsnfld !

 

Jojemar

One thing that I just noticed.

There are a number of different rounding methods (see this Wikipedia article)

Number.ToRound, by default, uses the so-called "round half to even" method (as does Excel VBA)

The rounding produced by the text function uses, I believe, the "round half away from zero" method (as does regular Excel).

 

In comparing the two, the Number.Round rounding method can be set explicitly as an optional argument.

 

So if you wanted to use a particular rounding method other than the default, you could probably round first, then format as text with two decimals.

Whaaaaaaat?!?!

That is pretty darn slick.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
watkinnc
Super User
Super User

I suppose the proper solution would involve List.TransformMany, but I've not yet used it. But you can probably wrap the whole List.Transform in another List.Transform, like

 

each List.Transform(List.Transform(List.Select([All][Cost Per Unit],  each _ > 0), Currency.From), Number.Round(_, 2)))

 

--Nate

 

 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Hi Nate,

 

I tried your suggestion above but it gives an error:

 

LarsAustin_0-1645313612024.png

 

I'm happy with the previous solution. Not being able to round to 2 decimals is not a biggie for my requirements for now. But i really appreciate you putting the time and effort to provide the desired outcome to my problem.

 

Big thanks.

 

Jojemar

 

watkinnc
Super User
Super User

Sorry about that! Replace Currency.Type with Currency.From.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Hi Nate,

 

Thanks for that. I get a much better result than the original outcome but how can this be rounded further into 2 decimals?

 

LarsAustin_0-1645302390880.png

LarsAustin_1-1645302453066.png

 

Thanks

 

Jojemar

 

watkinnc
Super User
Super User

Have you tried wrapping the List.Select with List.Transform like:

 

 each List.Transform(List.Select([All][Cost Per Unit],  each _ > 0), Currency.Type)))

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Hi Nate,

 

I tried your recommended solution but it gives an error as below:

 

LarsAustin_0-1645300376750.png

 

Thanks

 

Jojemar

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors