Running Total with Slicer from another table - powerbi

I have a running total dax measure that works. Problem now is that the slicer on the page is coming from another data set which is linked to the source table of running total data set and when you select the slicer it doesn't filter anything.
Homes Connected =
CALCULATE (
SUM ( refv_FTTH_HomesConnected[ActualHomesConnected] ),
FILTER ( ALL ( refv_FTTH_HomesConnected ), refv_FTTH_HomesConnected[Month_sort2] <= MAX ( refv_FTTH_HomesConnected[Month_sort2] ) )
)
Is there a way to incorporate the columns from the other dataset to get the desired result?

The ALL in your FILTER removes any slicer selection filtering.
Try using ALLSELECTED instead.

Related

How to pass multi column to remove filter using All in Dax formula in power bi

I have one requirement where I need to overwrite the filter context using All key word in Power bi Dax
In the table there are two value columns: Sales and Purchase and one date column .My calculation is based on these column
Simply dividing Sales by Purchase .But there are many attributes column with text values I want to remove the filter context for Purchase calculation .My data will look like below
My Dax formula looks like this:
measure_name =
CALCULATE (
SUM ( table_name[Sales] ),
YEAR ( table_name[Date of entry] ) = MAX ( YEAR ( table_name[Date of entry] ) )
)
/ CALCULATE (
SUM ( table_name[Purchase] ),
YEAR ( table_name[Date of entry] ) = MAX ( YEAR ( table_name[Date of entry] ) ),
ALL ( table_name[Attribute1] ),
ALL ( table_name[Attribute2] ),
ALL ( table_name[Attribute3] )
)
here I have put all attributes in the dax simply putting coma which will throw error
Any one can help me how to write this .Only for purchase(denominator calculation ) I want to remove the filter for any number of attribute columns.Or is there any other way to do this calculation .This data is dummy data .In future if we are getting more attributes , can we pass one list for this All parameters .So that user will just update in the excel all attributes and when it get refreshed , these parameter values to pass in to this All parameter automatically..?

use data slicer to distinct count in DAX PowerBI Desktop

I have two columns Month and ID a want distinc count per each month, but once I use data slicer to show data it shows as count distinct per select period
For example I have
I have
I used :
COUNT_ID = distinctcount('ID'[DATA])
once I select in data slicer 202207 & 202208 I get distinct values 4:
WANT
but I want result 5 because
202207 distinct values 2
202208 distinct values 3
I want to use this logic for whole data set once I select specific period.
Has anybody can help with?
Ids =
SUMX (
VALUES ( 'Table'[Month] ),
CALCULATE ( DISTINCTCOUNT ( 'Table'[ID] ) )
)

DAX TREATAS filtering by another table to get sales of all products on promotion

How to filter all products on promotion? Say we have two tables Sales and Budget without physical relationship. Here model is simplified and let's assume that it is the case, we cannot create physical relationship. We have to use virtual relationship.
We can see summary:
The two first columns are of the Sales table. The third column BudgetTreats is a measure:
BudgetTreatas =
CALCULATE (
SUM ( Budget[amount] ),
TREATAS (
VALUES ( Sales[id] ),
Budget[id]
)
)
Now I would like to resolve two things:
How to make a slicer to filter out only the products (id) which have BudgetTreatas?
How to create a measure for calculating sales but only for products which have a budget? So analogous measure as BudgetTreatas presented above.
And of course sample data: DAX TREATS.pbix
I posted an answer to my question but it is not to show an answer but rather to show working solutions, and give you idea on expected results. I would be grateful for any answer or comments.
References:
The Logic behind the Magic of DAX Cross Table Filtering
Virtual Filters Using TREATAS
How To Use The TREATAS Function - Power BI & DAX
Creating Virtual Relationships Using TREATAS - Advanced Power BI Technique
Measure calculating Sales filtered by ids in Budget table.
Surprisingly this is not working:
//not working:
SalesFilteredByBudget1 =
CALCULATE (
[Sales],
TREATAS ( VALUES ( Budget[id] ), Sales[id] )
)
It seems we need an extra table. If we add to the model a Bridge table with all sales id and connect it to Sales table on id (without connecting it to Budget table!) we may resolve the issue.
//works:
SalesFilteredByBudget2 =
CALCULATE (
[Sales],
TREATAS ( VALUES ( Budget[id] ), Bridge[id] )
)
So it seems filters propagate further from tables used in TREATAS( VALUES on the tables connected by physical relations.
If we want to make a measure without Bridge table we can make extra table as a table variable.
// works:
SalesFilteredByBudget3 =
VAR Lineage =
TREATAS ( VALUES ( Budget[id] ), Sales[id] )
VAR tbl =
CALCULATETABLE ( Sales, KEEPFILTERS ( Lineage ) )
VAR result =
CALCULATE ( SUMX ( tbl, [amount] ) )
RETURN
result

How do I average a column of values while excluding rows that contain a certain value from another column? PowerBi

I am trying to write a code for a data table in Power BI that averages values of a table but categorizes them based on ID and Project but at the same time exclude a value from another column. Below is what I am trying to accomplish and column AVG is the goal. Excluding Type = "II" and averaging the values based on category columns [ID] and [Project].
Below is the code I am working on but it is incorrect. What would be the best solution?
AVG =
CALCULATE (
AVERAGEX ( FILTER ( Table, Table[Type] <> "II" ), Table[Values] ),
ALLEXCEPT ( 'Table', 'Table'[ID], 'Table'[Project] )
)
How about this?
AVG =
CALCULATE (
AVERAGE ( Table[Values] ),
ALLEXCEPT ( Table, Table[ID], Table[Project] ),
Table[Type] <> "II"
)
I don't see a reason to use an iterator function (AVERAGEX) and a simple Boolean filter should work how you want (instead of using FILTER).

Cumulative total by group in Power BI (DAX)

After googling for two pages, I'm struggling to find a simple way to create a cumulative sum measure by date and item in Power BI (using DAX). I have a table which contains:
Username
Date (DD-MM-YYYY)
Number of requests in that day
I have managed to obtain the cumulative sum by using the following expression (extracted from DAXPatterns):
CALCULATE (
SUM ( Table[Requests] ),
FILTER (
ALL ( 'Date'[Date] ),
'Date'[Date] <= MAX ( 'Date'[Date] )
)
)
But I would like to obtain a measure indicating how many requests have been made by a user up to a certain date.
Is there a simple way to do this?
Create calculated table using SUMMARIZECOLUMNS function and apply filter that you need on the top of that calculated table.
YourCalcTableName =
SUMMARIZECOLUMNS (
'UsernameTable'[Username],
'Date'[Date],
"Number Of Requests", SUMX ( 'UsernameTable', 'UsernameTable'[NumberOfRequests] )
)
This calculated table essencialy produces 3 column table with user name, date and number of requests sent by this user on this date.
SUMMARIZECOLUMNS