How to filter a table for distinct values Powerapps - powerbi

I am new to Powerapps and I have noticed that the Distinct function returns a table of the distinct values(only returns the distinct column not the full row). Is there a way to filter a table so that it returns back a subset of the full table with distinct values in a specified column.

You can use the GroupBy function for this. Take a look at the documentation, or in the example below:
Assuming that cities is a table with the following values:
City
Country
Population
London
UK
8615000
Berlin
Germany
3562000
Madrid
Spain
3165000
Rome
Italy
2874000
Paris
France
2273000
Hamburg
Germany
1760000
Barcelona
Spain
1602000
Munich
Germany
1494000
Milan
Italy
1344000
The expression GroupBy(cities, "Country", "Cities") will return a table with a column "Country", and a column called "Cities" whose value will be a table with all cities for that country.
You can then use functions such as AddColumns and Sum to aggregate the values of the inner table, like in the example below:
AddColumns(
GroupBy(cities, "Country", "Cities"),
"Sum of City Populations",
Sum(Cities, Population))
In your tweets example, if you want to get one tweet from each day, you can have an expression like the one below:
AddColumns(
GroupBy(Tweets, "crf1d_date_index", "Dates"),
"SampleTweet",
First(Dates))
Where it would have a new column with the first tweet from each date. Or if you want a single field from the group, you can have something like this:
AddColumns(
GroupBy(Tweets, "crf1d_date_index", "Dates"),
"FirstTweetTime",
First(Dates).tweet_time)

Related

Merging Column results to as a parameter in paginated reports

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.

in PowerBI - How to group a table by a column, and return all unique values (coma seperated) from another column as grouped

I am trying to group a table by a column, so the resulted table have unique values in that column, and also returns all the unique values from another column that belonged to the grouped column:
Source:
Country = USA
Cities =
New York
Boston
Chicago
Houston
Transform: group by [Country] column, and return unqiue values from [Cities] and coma seperated:
Country = USA
Cities = New York,Boston,Chicago,Houston
thanks a lot
You can simply use CONCATENATEX in a measure
Measure = CONCATENATEX(VALUES('Table'[Cities]),'Table'[Cities],",")

Power BI create 2 dropdown slicer on same table two columns

I need to have 2 dropdown slicers, on the same table. For example, consider the following table:
Country
State
India
PUNJAB
India
DELHI
USA
CALIFORNIA
USA
TEXAS
I want the first slicer to show a single selection of Country as a dropdown and the second Slicer to show State based on Country. For example, if India is selected then the second slicer should be showing PUNJAB and DELHI.
How do I achieve this, currently if I select any state say PUNJAB, the country is also getting filtered and changed to INDIA and I am not able to select USA.
You can go to Edit interactions under the Format pane and edit the second slicer to not cross-filter the first one.
Alternatively, you could use both in the same slicer as a hierarchy.

Power BI how to create new column in date table based on conditions and reference to another table

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.

Sum based on two columns from another table

I've got this table named "A" and I want to fill the Sales SUM column with the sum of sales from another table group by date and country. The other table is named "B" and got also Date, Country and Sales columns however the number of dates and countries differ. I don't want to join this tables I would like to achieve this in DAX. Is it possible?
Yes you can do that with DAX and virtual relationship:
SumSales = calculate( sum('B'[Sales])
, TREATAS(SUMMARIZE('A','A'[Date],'A'[Country]), 'B'[Date],'B'[Country])
)