I have the data in the following format.
CompanyID Company Name
1 Nike
2 Adidas
3 Puma
I need to create a column and use it in X axis of a line chart or any visual for that matter in such a way that if a user from Nike logs in, in the visual he should "Nike" instead of companyID. But, for others he should the CompanyID.
Just add a new conditional column in Power Query or a computed column in DAX and use it instead of Company Name.
With Power Query:
With DAX:
Custom Company Name DAX = IF(Companies[CompanyID] = 1, Companies[Company Name], CONVERT(Companies[CompanyID], STRING))
Report data:
Report visuals:
Related
I would like to separate Dublin to other cities like Manchester, St Albans (grouped as UK). How should I do this? There's no country data for this
I have tried adding the city from query designer, and editing the available values as "specify values" is not working
Can you create a new DAX measure column , with a condition such as
NewCountryColumn = IF(Table[Location] = 'Dublin', 'IRELAND', 'UK')
Then you'll see a new measure column, which will have IRELAND for DUBLIN and rest all will be shown as UK , use this column to do your filter.
I pulled data into Power BI from a SQL query which returns only the order year in one of the columns. In Power BI I formatted the column as "Data type Date" and "Date time format 2001(yyyy)", but when I pull that column into a table in Power BI, it's clearly calculating 2020 and 2021 as the number of days from 1/1/1900 (like excel) because it shows the year as 1905 for both when inserting this column into a visual, instead of years 2020 and 2021.
How can I format this column as the year 2020 and 2021?
Thank you,
You can convert it in the data source, or you can add a custom column in Power Query with M, or a calculated column in the model with DAX. If your data is not too much, it doesn't really matter where you will do that, but the general recommendation is to do that as close to the data source as you can (i.e. if you can, add it to your query, or if you can't add a calculated column).
The data source option needs a column in your query, which can be added with expression like this (this one uses DATEFROMPARTS T-SQL command, if you are using another database, you will have to change it):
DATEFROMPARTS(ExistingYearOnlyColumn, 1, 1)
Or click Transform data to open Power Query Editor and click Add Column -> Custom Column:
and use #date to create the date:
The last option is to create a calculated column in DAX, by right-clicking on your table and selecting New column:
And use DATE DAX function in an expression like this:
DateColumn = DATE([ExistingYearOnlyColumn], 1, 1)
I have a Power BI table with some columns as given below:
Table1 - Columns(Project, Program, Name, Attribute, ID)
Example of table1:
Now I have a different measure which is used to view Power BI report. It also has some fields as given below:
Measure1 - Columns(Project, Name, Attribute, and few more)
Example of Measure:
Now I want to add ID (which is available in Table1) as Measure1 is being used to view report. How can I display ID based upon Name and Project.
Can anyone guide or help how to solve it?
If you can do this in your source Database using left join between this 2 tables.
If not, then you can use virtual relationship in DAX:
Display_ID = CALCULATE(min(Table1[ID]), TREATAS(VALUES(Table1[Project]), Measure1[Project]), TREATAS(VALUES(Table1[Name]), Measure1[Name]))
I am using SQL server data base. I need to display total no of nights based on checkindate and checkout date. i am new in Power BI.
I tried by quick measure but it is not working.
You can do this in different ways - calculate the duration in the database, add custom column in M or column in DAX.
In SQL Server use select query like this:
select checkindate, checkoutdate, datediff(day, checkindate, checkoutdate) as duration from table
In M (Power Query) - click Edit queries to open Power Query editor and then Add Column -> Custom column:
Duration.Days(Duration.From([checkoutdate]-[checkindate]))
In DAX - right click your table and select New column:
Duration_DAX = DATEDIFF('Table'[checkoutdate]; 'Table'[checkindate]; DAY)
Note, that depending on your settings, you may have to use comma (,) instead of semicolon (;) in the DAX expression above.
I am building a report in Power BI Desktop, created a slicer - YearMonthSort - which has data selection by Year-Month
Plz, see the screenshot below:
My goal is to limit data in this slicer as -
2015-07 to today's date
(whichever it will be when users will look at the data,
in the same format - "YYYY-MM")
In the "Filters" section I can select my starting year as 2015-07,
but having problem setting today's date.
I tried to create the new Measure, but not sure where to place it,
or, may be there is another way to perform this:
IsToday = FORMAT(TODAY(), "mm/yyyy")
I only just started to learn this,
Thank you for help in advance!
You can do the following:
I am assuming that you are using a calendar table that is joined to your fact table on a date field and that your year sort column is calculated with reference to the 'date' field in your calendar table.
Assuming, this is true you can create a calculated column that will flag whether or not the date field is before or after today. This can be achieved by using the following DAX:
IsToday =
SWITCH (
TRUE (),
'Calendar'[Date]
<= NOW (), 1,
0
)
Then, in your visual add a 'Visual Level Filter' using this new column and set it to 1.