Filter values based on other column in Power BI - powerbi

In Power BI I'm trying to combine and get the unique values of pages in a new table. I need to filter one of the columns, based on a value of another column in that same table. So i want to do something like
FILTER(VALUES('Table1'[URL]), 'Table1'[Correct] = "Yes"
But it's not working, because I can only filter based on calculations, not columns.
The complete line that I have now and is working is:
All pages = FILTER(
DISTINCT(UNION(VALUES('Table1'[URL]),VALUES(Table2[Complete URL]),
VALUES('Table3'[URLs]))), [URL] <> BLANK())
How can I add a filter to one of those tables, based on another column of that table?

You can just replace FILTER with CALCULATETABLE:
CALCULATETABLE(VALUES('Table'[URL]), 'Table'[Correct] = "Yes")
If you need to count the values, just wrap it into COUNTROWS:
Measure = COUNTROWS( CALCULATETABLE(VALUES('Table'[URL]), 'Table'[Correct] = "Yes"))

Related

Making DAX calculated table respond to filters on other table

I have a DAX table "Sumtable" that calculates the the number of rows in "Maintable" for two cases: (1) all rows in Maintable and (2) the subset of rows where Cat = "A".
Sumtable = {
("Full set", COUNTROWS(Maintable)),
("Subset", COUNTROWS(FILTER(Maintable, Maintable[Cat] = "A")))
}
I want to viz Sumtable and make it respond to filter settings on Maintable. For example when I select Maintable[Sex] = "Male" the totals in Sumtable should reflect that. What is the right way to accomplish this?
For example when I select Maintable[Sex] = "Male" the totals in Sumtable should reflect that.
Just make this two measures instead of a calculated table.
If you want these measures to appear under Sometable, you can create a one-row, one-hidden-column table with two measures, instead of two calculated columns.
And when you hide all the non-measure columns on a table it becomes a "Measure Table" with a differentiated icon.
Solved it with this: analytics-tuts.com/bar-chart-using-measures-in-power-bi

PowerBI - How to show only 10 categories and wrap the rest on "Others"

I have a customer service ticket list and need to build a report with it, one of the charts must be a "Qty per motive" and the problem is that I have too many motive to show on a chart, so I want to show let's say 10 of them and wrap the rest on a "Others" categories.
I've found some posts showing hot to do this with values like Sales, but I couldn't figure out how to make it work with a count on my data.
the structure of the data is like
ClientID | Ticket ID | Date | Motive | Description
In the posts that I've found the solution involves a SUM() and then sorting by the SUM() column, but I don't have a value column, I need to count per motive
There are a couple of ways to doing that.
New group
use built-in PBI feature that you have to manually set up. Right-click on a column name in the Fields section and chose New group. A new window will pop up. There, you have to choose the categories you want to label as others. A new field (Column name (groups)) will appear in your table. This method requires you to decide arbitrarily which columns you want to be displayed.
Create calculated table
You could create a brand new Calculated table in your model that is going to set new labels based on the total quantity. In that case, the labels will dynamically change rather than being static. If new motive comes to the model and its quantity will be in TOP N then it will be visible on the chart. This solution creates a separate table that you have to connect via relationship with your main table later.
Select Calculated table on the ribbon and then write DAX:
TopNCategories =
VAR keepLabels = 3
VAR tbl =
ADDCOLUMNS(
VALUES( 'Product'[Brand] ),
"#TotalSales", CALCULATE( [Sales Amount] )
)
VAR addRank =
ADDCOLUMNS(
tbl,
"#Rank",
RANKX(
tbl,
[#TotalSales],
,
DESC
)
)
VAR result =
SELECTCOLUMNS(
addRank,
"BrandKey", 'Product'[Brand],
"NewLabel", IF( [#Rank] <= keepLabels, 'Product'[Brand], "Others" )
)
RETURN
result
Calculated column
If you don't want to create another instance in your model, you can use the above logic to create a set of Calculated column in your main table instead. Depends on your model size and cardinality, this solution may have an impact on the performance of the whole report.

I need to filter a table using dax command or other power bi methods

I need to filter the table so it can look like the image.
I need to filter out the table so that if (leave*3)<remain only those outputs should be shown.
I tried to use a calculated column and used dax:
remain_find =
var remaining = Voting[Remain]
return IF(Voting[3 x leave] < remaining, remaining)
But it shows blank where the condition fails. I need to do this without any blanks.
Add your measure to the filters of the Visual.
Set the filter on the measure to exclude blanks:

Power BI slicer OR condition

The interaction between two slicers in Power BI gives me output with AND condition.
Example: If I selected the year 2020 and company ABC, the output would be all the data from company ABC in the year 2020.
But I want the two slicers to work with OR condition.
I have used this Dax
Include = (MAX(Table1[Column1]) = SELECTEDVALUE(Col1[Column1])) +
(MAX(Table1[Column2]) = SELECTEDVALUE(Col2[Column2]))
But the problem with above Dax I have not selected anything in slicer ( ALL by default) it is showing me a blank visual. What am I doing wrong?
let me guess you have a table "or_slicer_main_table" with Year, Company and some other columns. Now create 2 new table where the first one will contain the distinct list of Year from table "or_slicer_main_table" and the second one will contain distinct Company list from that same table.
New custom Table 1:
or_slicer_year_list =
SELECTCOLUMNS(
'or_slicer_main_table',
"YEAR", 'or_slicer_main_table'[year]
)
New custom Table 2:
or_slicer_company_list =
SELECTCOLUMNS(
'or_slicer_main_table',
"company", 'or_slicer_main_table'[company]
)
Do not establish any relation between those 3 tables.
Step-1: Create Year slicer using the newly created "or_slicer_year_list" table.
Step-2: Create Company slicer using the newly created "or_slicer_company_list" table.
Step-3: Create these following 5 measures in your table "or_slicer_main_table"
1.
year_current_row = max('or_slicer_main_table'[year])
2.
year_selected_in_slicer = SELECTEDVALUE(or_slicer_year_list[YEAR])
3.
company_current_row = max('or_slicer_main_table'[company])
4.
company_selected_in_slicer = SELECTEDVALUE(or_slicer_company_list[company])
5.
show_hide =
if(
[year_selected_in_slicer] = [year_current_row]
|| [company_selected_in_slicer] = [company_current_row],
1,
0
)
Now you have all instruments ready for play. Create your visual using columns from the table "or_slicer_main_table"
Final Step: Now just add a visual level filter for the measure "show_hide" and set value will show only when "show_hide = 1".
The final output will be something like below image-
Can you try using "IN VALUES" instead of "SELECTEDVALUE"
So your DAX should be
Include = (MAX(Table1[Column1]) IN VALUES (Col1[Column1])) +
(MAX(Table1[Column2]) IN VALUES (Col2[Column2]))
SELECTEDVALUE function returns the result only if single value is selected in slicer in case of multiple selection it will return Blank(). Thats in the case when nothing is selected (which is similar to all selected) has multiple values in set and so SELECTEDVALUE fucntion will return Blank(). This can be handled by using "IN VALUES" function which can return a set of all selected values.

Convert SQL query to DAX query used in power bi to find the row with max date for a specific id

I want to make a report in power bi, for which I need to find the latest record for all ids.
This is the SQL query that can be run on the table to achieve this:
SELECT * FROM placement
WHERE dateModified in (
SELECT max(dateModified)
FROM placement
GROUP BY ID
);
How can I achieve the same in Power BI using power query or DAX?
You can use the FILTER Function like this:
FILTER(placement, dateModified = MAX(placement[dateModified]))
not sure about the syntax, but if you provide some data we can check that is compiling.
I would probably use a report level filter on a calculated column:
IsTopDate = IF(table1[Date] = Calculate(Max(table1[Date]), All(table1)), 1, 0)
Then add top date as a report level filter on 1.
OR
Using PowerQuery, do something like so using Table.Column, List.Max and Table.SelectRows:
#"maxDate" = List.Max(Table.Column(#"Source" as table, "Date" as text) as list ),
#"Filtered Rows" = Table.SelectRows(#"Source", each [Date] = #"maxnum")