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
dbrandone
Helper III
Helper III

Power Query Issue - Add Column only showing null values

Hi everyone,

 

I have a table that I am trying to add a column in power query. I have a similar table that the code (similar code) worked just fine, but for some reason this column is only showing null values which is from the "else" statement. I made sure that all of my data types were correct and that the values in the if or else if statements match (they are only one letter). Thinking that maybe another set of eyes would help. I am trying to make all ages whether they were inputted at the datasource (measured) as Y(Year), M(Month), W(Week), or D(Days), to be relative to one another. This has me stumped. Below is the power query formula I wrote and a picture of the columns that I am referencing. 

 

Table.AddColumn(#"Changed Type2", "Age(Yrs)", each if [Age Measurement] = "Y" then [#"Age (Don't Use)"] else if [Age Measurement] = "M" then [#"Age (Don't Use)"]/12 else if [Age Measurement] = "W" then [#"Age (Don't Use)"]/52 else if [Age Measurement] = "D" then [#"Age (Don't Use)"]/365 else 0)

 

dbrandone_0-1658158240088.png

The Age(Yrs) column that I am trying to create should pull over the value from the "Age (Don't Use)" column if the Age Measurement is Y, Divide the Age(Don't Use) column by 12 if the Age Measurement is M, and so on for W(Weeks) and D(Days).

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@dbrandone Maybe try trimming and cleaning your Age Measurement column?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@dbrandone Maybe try trimming and cleaning your Age Measurement column?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

 

Thanks, trimming worked. I tried cleaning first, and it did not but trimming did. Can you explain what that did? None of the values seem to have changed? Is this a background data change?

@dbrandone Trimming gets rid of white space or essentially blanks/non-printing characters.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.