How do I convert a number from data type TEXT to whole number to further calculate it using DAX? - powerbi

I am taking data from the excel where there is a column "Global" with values as whole numbers and decimal numbers. When I am importing it to Power BI, the column data type is coming as "TEXT" and hence I am unable to use it to calculate my new column which is "Local + Global / Total" since it cannot convert calculate on string which makes complete sense.
I looked it up and tried the following :
To change the column type to Whole Number / Decimal Number and it showed me an error that It cannot be converted.
I made a measure using the functions CONVERT and VALUE but in vain. It could not be converted saying a single value was expected but multiple values were provided in the latter.
How do I solve this?
EDIT
The column looks like this
Global
12345.67
43566
123.765

If it is showing error that It cannot be converted, obviously there are some garbage value in the column like - space, string or other values not a number. Please check your data first, hope you will get the issue as well.
In Power Query Editor You can select the column and change data type to Whole Number. In that case, some errors will be shown where the conversion failed to convert some value as shown below-
Here I have provided a string in the last row. Now you can check your data by filtering the column with error to check what are the actual values in the source. You can than perform some transformation to get the correct value value out of them.
You can also remove all records with error as shown below if you find those rows are with garbage value is not important for your.

Related

Excel formula that checks the text of a specific column and the text of a specific row and returns the data listed in the table

I am trying to display the outcome scores on one Excel sheet into another Excel sheet based on the outcome name and course.
If the text in Sheet1!C2=communication and Sheet1!E2=Comm 2010, then display Sheet1!D2 on Sheet2!B3.
If the text in Sheet1!C4=information* and Sheet1!E4=Commm 3000, then display Sheet1!1D4 on Sheet2!C5.
Need to be able to use Wildcard when checking the text.
If the text in Sheet1!C6=communication and Sheet1!E6=Comm2010, but there is no number in Sheet1!D6, leave Sheet2!B5 blank
I have played around with a few different IF AND formulas, but I can't get the data displayed correctly.
Right now, I am building a pivot table from the data in Sheet1, then taking the table and formatting it to match the table on Sheet1 then using =IF(Pivot!C7="","",Pivot!C7). This works, but building a pivot table for each student and then formatting it to match Sheet1 is a time drain.
I'm really hoping there is a better way to do this.
Thank you!
Since you are compiling outcomes on a per-student basis and not in total it is safe to use the SUMPRODUCT() function:
The formula below is used in B3
=SUMPRODUCT((Sheet1!$E$2:$E$6=Sheet2!B$1)*(Sheet1!$C$2:$C$6=Sheet2!$A3)*(Sheet1!$D$2:$D$6))
and can be copied across and down throughout B3:C4
The formula used in B5 is different, because of the 'wildcard criterion'
=SUMPRODUCT((Sheet1!$E$2:$E$6=Sheet2!B$1)*(LEFT(Sheet1!$C$2:$C$6,11)="Information")*(Sheet1!$D$2:$D$6))
(unless you are using Microsoft 365, having the formula directly suppress 0 values essentially entails doubling it in length so, as an alternative, given the small output range, a custom-number format has been implemented, which effectively doesn't display 0 in a cell where that is the formula result)

Dax Related function returns all zero column

I have 2 tables which are related in a one-to-many fashion.
When I use related with string value columns as store name or even integer value columns it works fine and brings the correct value.
However when I try to bring the column I am interested in ("number of clients"), which is a numeric column, it only brings a column with 0 values.
I transform the column to string and even in that case it returns all 0 string value. Even if I concatenate the column with another string column like "store name", it will return the correct store name but with the number of clients transformed to zero.
I have compared the properties of the other numeric columns that work well with related and they seem to have the same settings. I have seen posts about people having trouble with related functions so I made a new report and imported the 2 tables again but the same thing happens.
Also when trying with lookupvalue I face the same issue.
please help!
Edit: here is an example of the situation with data
So in the background I have the table of the many side of the relation. I have added 2 columns, one in which the related function works, by bringing the client type data and the other one that doesn't work which should bring the number of clients data. ** the numbers of client type don't match in the shown tables because of the one to many relation.
In the front I placed a sample of the number of clients table where the client type and the number of clients are shown.
So both of the columns from client number table are numerical but somehow one column gets related correctly and the other one gets transformed to only zero values.

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.

Power BI How to Sum Based on If a Column Contains String from Other Column

I have an Entity column with one row per entity. This table has three columns: Entity ID, a Descriptor, and a Metric. The Descriptor is a concatenation of numerous codes and I would like to see the metrics broken down by code.
I originally just split the Descriptor column into numerous rows but that led to some data relationship issues so I'd like to do it without splitting the Descriptor column.
I tried doing the following DAX formula but it resulted in an error stating "the expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression"
Desired Output Metric = CALCULATE('Metric',CONTAINSSTRING('Entity Table'[Descriptor],'Code Table'[Code]))
Ultimately I'm not even sure I need this as a column, and it may be better as a measure...
Any help would be appreciated. Thank you!
You can get around "the expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression" by using Filter within your CALCULATE.
Here it is as a created column. I used an IF because 'E' code evaluates to a blank and you wanted a 0.
Desired Output Metric = IF(CALCULATE(SUM('Entity Table'[Metric]),FILTER('Entity Table',CONTAINSSTRING('Entity Table'[Descriptor],'Code Table'[Code])))>0,CALCULATE(SUM('Entity Table'[Metric]),FILTER('Entity Table',CONTAINSSTRING('Entity Table'[Descriptor],'Code Table'[Code]))),0)
Here it is as a measure. Be careful to only use this at the Code detail level. When making a measure you need to use aggregate functions to reference your columns, so I am just doing the MIN(Code) since for any single code the Min() will always evaluate to equal that Code. If you try to use this at a higher summary level you may get some odd answers as it will only total for the MIN() code in the data set you are referencing.
Desired Output Metric = IF(CALCULATE(SUM('Entity Table'[Metric]),FILTER('Entity Table',CONTAINSSTRING('Entity Table'[Descriptor],MIN('Code Table'[Code]))))>0,CALCULATE(SUM('Entity Table'[Metric]),FILTER('Entity Table',CONTAINSSTRING('Entity Table'[Descriptor],MIN('Code Table'[Code])))),0)

Power BI Desktop doesn't honor percentage column type

I've imported data (approximately 200 columns) into Power BI desktop (latest version as of 2017-08-02) and have explicitly told the app to treat a number of columns as being percentages. Within the query editor, I can verify that my values are treated as such:
When I put my data into a table, they show up as normal floats, not percentages. When I click on the exact same column as in the above picture and view it in the Modeling tab, Power BI shows it as being "General" format:
While I can go through and change the formatting here to have them all be percentages, I have already done so in the query editor! Is there a way to make PBI recognize my already specified format?
Short answer: No.
Explanation:
In the query editor, you didn't actually specify any format. What you specified is the data type, so that the source data can be read correctly. Say you have a column with data like 001, you can specify it as text type so you can retain the leading zero.
However, the actual formatting (i.e. data presentation) is done in your second step, because even if it's a (decimal) number, you can still format it as a percentage, with different decimal places, etc. (vice versa)