I'm relatively new to Power BI and want to generate a new one based on a column. The contents of the new column should be based on the first value of another column. For example:
ColumnA NewColumn
1123 Argentinia
5644 Brazil
5555 Brazil
3334 Denmark
1124 Argentinia
As you can see, the first value of the number decides which country will be added to the new column.
In SQL I know that I can use something like this:
`select * from table where column LIKE '%[2]`%'
and so on but is this possible with Power BI? Thanks a lot.
Edit:
My additional list looks like this:
ID Country
1 Argentina
2 Swiss
3 Denmark
4 Norway
5 Brazil
and so on...
I thougt I could use somethin like this:
NewColumn = IF('table'[ColumnA] = "%[1]`%"
THEN "Argentinia"
ELSE if IF('table'[ColumnA] = "%[2]`%
THEN Swiss
ELSE "No Country")
Add your Number / Country List to a new table. Let's assume you call it Countries.
Now you can add a column to your original table (let's assume you've called that one Fact Table), using something like:
Country =
LOOKUPVALUE (
Countries[Country],
Countries[ID],
VALUE ( LEFT ( 'Fact Table'[ColumnA], 1 ) )
)
See https://pwrbi.com/so_56391689/ for worked example.
Okay, I've now also found a solution:
NewColumn = SWITCH(TRUE();
LEFT(table[ColumnA]; 1) in {"1"}; "Argentina";
LEFT(table[ColumnA]; 1) in {"2"}; "Swiss";
LEFT(table[ColumnA]; 1) in {"3"}; "Denmark";
LEFT(table[ColumnA]; 1) in {"4"}; "Norway";
LEFT(table[ColumnA]; 1) in {"5"}; "Brazil"
)
Works very well :)
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 have 2 data in Power BI- Table and Table 2.
I would like to know how can I achieve Table 3 from Table 1 and Table 2.
Thanks !
Tried using text.contains to search, but its taking too long.
Add 2 calculated colmuns to your Table:
City = RELATED('Table 2'[City])
Country =
IF(
'Table'[City] = BLANK(),
'Table'[Location],
RELATED('Table 2'[Country])
)
The resulting Table will look like this:
I am learning PowerBI as i go along and have been able to solve most issues faced by a quick google. Unfortunately this problem has baffled me.
We have thousands of lines of data which include a "Home Country" column & "Away Country" column.
What we need our slicer to do is to is to pick up for example Australia in both of these columns and display the results.
I currently have a table created using the below:
slicercountrytable = distinct(
Union(
Values('All Data'[Home Country]),
Values('All Data'[Away Country])))'''
and then a measure:
Measure =
if(
Min('All Data'[Home Country]) in values (slicercountrytable[Country])
|| Min('All Data'[Away Country]) in values (slicercountrytable[Country]),
1,
Blank()
)
And have also tried the below measure:
Measure 3 = VAR
Searchvalue=search(SELECTEDVALUE(slicercountrytable[Country]),SELECTEDVALUE('All Data'[Combined Country]),,Blank())
Return
If(Searchvalue > 0,"Found")
I need the slicer to control the entire sheet however the above are doing nothing.
Thanks
In that case, instead of building some complicated DAX I suggest to work the model.
Let's say your current table looks like that:
id
home country
away country
1
A
B
2
B
C
You may want to deal with that in another table by unpivoting home_country and away_country in PowerQuery.
In order to have a country table like that:
id
country
attribute
1
A
home
1
B
away
2
B
home
2
C
away
Then you link this new table to your existing one on id and filter/slice in it.
I reproduced your example and feel that it is already showing the desired behavior. I think the problem you might be running into is that you will now need to add your 'measure' filter to each and every visual individually. It cannot be added to 'Page' or 'All Pages' filter areas. This is because of the way a measure's calculation varies across context and cannot be avoided.
DAX
Table 2 = distinct(union(all('Table'[Away]), all('Table'[Home])))
Measure =
if(
MAX('Table'[Away]) in VALUES('Table 2'[SelectedCountries])
|| MAX('Table'[Home]) in VALUES('Table 2'[SelectedCountries]) ,
1,
blank()
)
I am having tremendous difficulty in getting around a Power BI function.
I am super new to Power BI and I've learned a lot already but I'm still confused about some topics.
I uploaded some data from excel into my Power BI applicaiton and it had some data as such.
Returns (Tab 1)
Order ID (column 1)
1
2
3
Orders (Tab 2)
Order ID (column1) Product ID (column 2)
1 100
1 101
2 101
3 101
3 100
4 100
Product (tab 3)
Product ID (column 1) Product(column 1)
100 Table
101 Chair
What I am trying to do is figure out the top 5 products that are returned.
I know the data above only has 2 products, but the actual data in my Power BI file has many more.
I basically want to take the Order ID from tab 1, compare them with the multiple product ID's each order has in tab 2 and then compare that with the product names in tab 3 to figure out the top 5 products that are returned.
I've already establihed all the relationships and linkages.
I've tried to use the "Top N", count distinct and sum functions but I was unable to get the filteration mechanism to work properly.
I kept on getting the total number. I also tried using matrix but that didn't work either.
You can access the file with this[link][1] in case anyone wants to look at the data I am working with to get a better idea of my problem. Page 3 is where majority of my attempts have been at trying to solve the problem.
I'm basically trying to find the top 5 most returned products, ideally in a graph and maybe using a slicer.
https://1drv.ms/u/s!AnMQvyG3G5w6iTcKZUaBvA_oLalv
That link above leads to the download page to downloads the PBIX file I am working with.
I would greatly appreciate any help.
First create a Table using this below DAX-
minimum_return_show =
VAR return_per_product_name =
SUMMARIZECOLUMNS(
Products[Product Name],
"return", count(Products[Product Name])
)
var top_n =
MINX(
TOPN(
5,
return_per_product_name,
[return]
),
[return]
)
return
TOPN(
1,
FILTER(
return_per_product_name,
[return] >= top_n
),
[return],
ASC
)
Now create a Measure as below-
product_count =
if(
count(Products[Product Name]) >= max(minimum_return_show[return]),
count(Products[Product Name]),
0
)
Finally create your bar chart using column product_name and measure product_count. Apply filter on product_count with greater than 0 and hopefully you will get your desired output.
I have a date table called 'dDate', it looks like below:
Date
01/01/2020
02/01/2020
03/01/2020
I have another table called 'Calendar', which looks like below. Note that not all dates are present in this table.
Date Holiday
01/01/2020 1
03/01/2020 0
I want to add a column 'HolidayDate' to the dDate table, where, for a particular date, a value of 1 is given if 'Holiday'=1 from Calendar, else a value of 0. So the HolidayDate column looks for the date in the Calendar table, checks if holiday is 1 and returns 1 if it is.
So the output in dDate table should look like:
Date HolidayDate
01/01/2020 1
02/01/2020 0
03/01/2020 0
I want to add a new column and specify a formula which achieves the above. How can I do this?
If Calendar and dDate has relationship, you can create the following calculated column in dDate
HolidayfromCalendar = RELATED('Calendar'[Holiday])
If Calendar and dDate has no relationship, you can create the following calculated column in dDate
HolidayfromCalendar =
CALCULATE (
MAXX (
FILTER ( 'Calendar', 'Calendar'[Date] = MAX ( dDate[Date] ) ),
'Calendar'[Holiday]
)
)
If you create a simple relationship between you source table with the date and the table with the calendar, then you can use the holiday date for the source table and PowerBI will make the join for you. You don't need to "copy" the holiday indicator across. In fact, the holiday indicator belongs with the calendar table, since this is effectively your date dimension in a Kimball model.
As per comment, if you model is not yours to change, or you have painted yourself in to a bit of a corner with complexity, you can resort to using LOOKUPVALUE to pull the data across. Keep in mind this may have a performance impact on huge data sets.