Forum Discussion
Support with simplifying my DAX code
- 5 years ago
I can almost guarantee this is not the best approach. Your formulas are using runtime (measures are runtime) text searches to segment your results. It is better to pre-segment the data in one or more columns in your tables, using power query (preferably) or calc columns. I suggest you investigate a conditional column in power query and see if you can generate a new single column that is loaded into the model that already has these new classifications.
I can almost guarantee this is not the best approach. Your formulas are using runtime (measures are runtime) text searches to segment your results. It is better to pre-segment the data in one or more columns in your tables, using power query (preferably) or calc columns. I suggest you investigate a conditional column in power query and see if you can generate a new single column that is loaded into the model that already has these new classifications.
EDIT:
I found another thread where you had helped someone else with the same issue here: https://community.powerbi.com/t5/Power-Query/Expression-Error-We-cannot-convert-the-value-null-to-type/td-p/1434783
I followed this advice by going back to my previous steps and checking for errors. I have now fixed this issue.
Thank you!
E
Hello,
I did as you suggested and I went back to Power Query. I created two conditional columns to search the ID column to begin with. This leaves me with columns that have values SEG, DTFA, G, WB90 and then 001, 002, 003, 004, 005 etc. Any columns that don't match either of these I just have 0 in that column.
I then created a third conditional column to bring these together and put the following formula in:
= if [Custom1]="SEG" or "DTFA" and [Custom2]="001" then "001" else if [Custom1]="SEG" or "DTFA" and [Custom2]="002" then "002" else if [Custom1]="SEG" or "DTFA" and [Custom2]="003" then "003" else if [Custom1]="SEG" or "DTFA" and [Custom2]="004" then "004" else if [Custom1]="SEG" or "DTFA" and [Custom2]="005" then "005" else if [Custom1]="G" then "G" else if [Custom1]="WB90" then "WB90" else ""
There is no syntax error however when I go to load that into my table I get the following error:
"We can not convert the value "DTFA" to type logical"
I went back to a step and formatted both custom columns to type text to fix this however no such luck.
Thanks,
E
- MattAllington5 years agoCommunity Champion
well the error suggests the column is being treated as logical in Power BI. I suggest you remove that column as the last step in PQ, then load. Then go back and remove this last step, and load again. See how that goes.