Filtered Running Total - powerbi

I am trying to get a running total of a count value in a table, but I need to have the filters I created to apply.
Basically I have 2 tables.
Table one is a user table which contains the user email (useremail) address and the user country (usercountry)
Table two contains the user email (useremail) and a date when they signed an agreement (Created)
I created a measure like this, which gets the user email from the signup table and gives me the running total, but when I apply a filter to the report, the sign up count does not change. It completely ignores the filter
Sign ups =
CALCULATE (
DISTINCTCOUNT( 'SignUps'[useremail] ),
FILTER (
ALLselected ( 'SignUps' ),
'SignUps'[Created] <= MAX ( 'SignUps'[Created] )
)
)
There is a relationship between the two tables where users(useremail) matches sign ups(useremail) One to One and cross filter both directions
Basically the chart below never changes regardless of the usercountry I filter by
Sign Up Chart.
Any idea how I can do this?

You won't need ALLSELECTED unless you are showing visual total.
Remove ALLSELECTED and just pass a table so it can be filtered using your slicer.
Sign ups =
CALCULATE (
DISTINCTCOUNT ( 'SignUps'[useremail] ),
FILTER (
'SignUps',
'SignUps'[Created] <= MAX ( 'SignUps'[Created] )
)
)
Read ALLSELECTED

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..?

Filtering by secondary field in DAX

I'm new to DAX.
My model contains a single table called Notices. Notices has 235,969 rows.
Notices has fields CustomerID, NoticeNo and NoticeStatus.
When I set the filter context to 'CANCL' Notices[NoticeStatus], I can see that there are 3 notices that have a CANCL status.
As such, the measure below evaluates to 3 since each of the remaining notices belong to 3 separate customers. However, I would like to base the aggregate on the unfiltered table, but filter out the rows (after aggregating) based on the CustomerIDs that remain in the filter context and [ObCount] = 1. In this case, the measure needs to evaluate to 0 or BLANK(), as none of the CustomerIDs in the filter context remain after filtering for [ObCount] = 1.
Customers with Single Notice Only =
COUNTROWS (
FILTER (
SUMMARIZECOLUMNS (
Notices[CustomerID],
Notices,
"ObCount", [All Notices Outstanding]
),
[ObCount] = 1
)
)
[All Notices Outstanding] = COUNTROWS(Notices)
You should be able to do this by applying the filtered table as a table filter argument to Notices using CALCULATE:
Customers with Single Notice Only =
CALCULATE (
COUNTROWS ( Notices ),
FILTER (
SUMMARIZECOLUMNS (
Notices[CustomerID],
ALL ( Notices ),
"ObCount", [All Notices Outstanding]
),
[ObCount] = 1
)
)
Note the use of ALL to remove the filter status filter when summarizing.

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

Running Total with Slicer from another table

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.

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