measure with date range - powerbi

I've a data model like the screenshot
here're the relationships between tables
I try to calculate count application by next_processing_date
Anta = calculate( sum(proposals[CountApplication]) , USERELATIONSHIP( proposals[next_processing_date] , DimDate[Date] ),FILTER(proposals, proposals[next_processing_date] >= 'Report Measures'[StartDate]&&proposals[next_processing_date] <= 'Report Measures'[endDate]))
But it returns always nothing
I analyze data it seems the issue related to the expresion of measure, how to correct it

Related

How do i bring userelationship in this calculation

I am trying to calculate the number of working days between 2 date columns in a table called Incident Table and the 2 columns are called Created Date and Resolved Date. I also have a standard date table.
Right now, the relationship is one to many between date and Created date column in Incident table
First I created a column in date table that would give true or false as to whether a day was a weekday
Is Working Day = if('Date'[Day Name Short]="Sat",FALSE(),if('Date'[Day Name Short]="Sun",FALSE(),TRUE()))
Then in the incident table i used this
Time to Resolve (days) = COUNTROWS ( FILTER ( 'Date', AND ( AND ( 'Date'[Date] >= 'Incidents'[Created Date], 'Date'[Date] <= Incidents[Resolved Date] ), 'Date'[Is Working Day] ) ) )
This formula is fine on its own but i need to connect resolved date with the date table so i can use date filter for both created and resolved. Any ideas?
You would ideally create two relationship from the Dates table with Incident table, one active and one inactive and then in the measure you would activate the inactive relationship using USERELATIONSHIP.
Something =
CALCULATE (
DISTINCTCOUNT ( Incident[Time to Resolve (days)] ),
USERELATIONSHIP ( Incident[Resolved Date], Dates[Date] )
)

PowerBI Filter Context Problems

I have a measure setup in Power BI, that is not behaving as I would expect and I'm trying to figure out what is missing here. The measure that I have defined is fairly straightforward and seen below.
Test Filter Removal =
CALCULATE(
SELECTEDVALUE('Report Options'[Operation Costs], "Costs "),
REMOVEFILTERS('Report Options'),
FILTER('Report Options', 'Report Options'[Operation Costs] = "Costs at Current Year Rates")
)
The table 'Report Options'[Operation Costs] has 2 options in it "Costs at Actual Year Rates" and "Costs at Current Year Rates". The context on the page for this report is that the Costs at Actual Year Rates is selected, but for this measure I want it to report Costs at Current Year Rates.
The full measure is more complicated then this, but the whole problem of the more complicated measure comes down to the fact that this part of the measure is returning "Costs " in this example, which is the default value being used in the SelectedValue function.
What I don't understand about this is that the filter specified is should be specifically setting it to Costs at Current Year Rates. I'm sure that the problem has to do with context, but I'm not seeing what it is.
Because all of the filter arguments in CALCULATE are evaluated with AND logic, REMOVEFILTERS isn't really doing any work here because your FILTER argument is a subset of that larger table.
I suspect you want something more like this:
Test Filter Removal =
CALCULATE (
SELECTEDVALUE ( 'Report Options'[Operation Costs], "Costs " ),
'Report Options'[Operation Costs] = "Costs at Current Year Rates"
)
which is equivalent to
Test Filter Removal =
CALCULATE (
SELECTEDVALUE ( 'Report Options'[Operation Costs], "Costs " ),
FILTER (
ALL ( 'Report Options'[Operation Costs] ),
'Report Options'[Operation Costs] = "Costs at Current Year Rates"
)
)
Note that without the ALL (like in your DAX), the table is evaluated within the filter context and is thus affected by the slicer and hence returns an empty table when the slicer doesn't include "Costs at Current Year Rates" for that column.

DAX - Get list from a filtered SUMMARIZE formula

So, I have the following tables in my Power BI :
Sales : Date | ID_Client | ID_Product | Amount
Client : ID_Client | Name_Client
I would like to get the number of unique BIG clients in any given month. I therefore use the following formula (which I then put in a column in a table with months in rows):
# BIG Clients =
VAR threshold = 10000
RETURN
(
CALCULATE(
DISTINCTCOUNT( Sales[ID_Client] ),
FILTER(
SUMMARIZE(
Sales,
Sales[ID_Client],
"Sales", SUM( Sales[Amount] )
),
[Sales] >= threshold
)
)
)
QUESTION IS : how can I get the list of those BIG clients for any given month? Let's say I click on the November number of big clients in my table, could another table nearby display the list of those clients ?
Thanks in advance for your kind help, I've been trying for a while :)
I assume that you have a table of clients with the Name column with a one to many relationship with the Sales table and that you do not have duplicate client names. Then you may create a [BIG Sales] measure to be used in a table or matrix visual with client names on the rows.
since [BIG Sales] evaluates to BLANK() for clients with less that threshold sales, they are automatically filtered out from the visual
BIG Sales =
VAR threshold = 10000
VAR BigCustomers =
FILTER(
ADDCOLUMNS(
VALUES( Clients[Name] ),
"Sales", SUM( Sales[Amount] )
),
[Sales] >= threshold
)
RETURN
SUMX(
BigCustomers,
[Sales]
)
You could create a table or matrix visual with the client on the rows and use your measure in the values field. This will show 1 for all big clients and return blank for the rest (which should hide them). If you don't want to show the measure, you can set the value is 1 in the filter pane and remove the measure from the values field.
A more direct option is to use a simple SalesAmount = SUM ( Sales[Amount] ) measure in the values field and filter like this

Distinctcount entrys with date slicer

this is probably pretty simple but I couldn't find any solution.
I have 2 tables: 'DateTime' and 'Usage' and I am using a date slicer (from to) which refers to 'DateTime'[Date]. Now I want to DISTINCTCOUNT 'Usage'[LPNumber] but only the ones which have a date that is included by the slicer. The table 'Usage' does also have a column with dates: 'Usage'[ConnectionStart Day]
I tried this but getting an error:
ActiveLP =
VAR start_date =
MIN ( 'DateTime'[Date] )
VAR end_date =
MAX ( 'DateTime'[Date] )
RETURN
CALCULATE(
DISTINCTCOUNT( 'Usage'[LPNumber] );
FILTER(
'Usage';
'Usage'[ConnectionStart Day] >= start_date
&& 'Usage'[ConnectionStart Day] <= end_date
)
)
The error says: A circular dependency was detected: DateTime[different columns]
Can someone please help me? Thank you very much :)
Just create a realtionship between your DateTime table and your Usage table (by the date). Then use this simple measure:
Distinct Count = Distinctcount('Usage'[LPNumber])
If you put now a slicer (from the DateTime table) on your report and filter it, the other table also get filtered, because of the relationship. Thus the value of Distinct Count will change, according to your date slicer.

Power BI - Running total column with many filters

I have table "Sales" (fields: Product, Country, Date, Sales) with monthly sales across many products and countries. Also I have tables with calendar, list of products, list of counties that are linked with this table. I want to add column to "Sales" with running total sales across each Product/Country, see the field with desired result "Running total".
I tried to use
YTD = TOTALYTD(SUM(Sales[Sales]); Calendar[Date]) but it didn't work. I think I need to use filters in TOTALYTD function, but I also didn't manage to understand how. Can you suggest to me a right solution to my case?
Table "Sales"
I was suggested to use this code
Column =
SUMX (
FILTER (
Sales,
Sales[Product] = EARLIER ( Sales[Product] )
&& Sales[Country] = EARLIER ( Sales[Country] )
&& Sales[Date] <= EARLIER ( Sales[Date] )
&& YEAR ( Sales[Date] ) = YEAR ( EARLIER ( Sales[Date] ) )
),
Sales[Sales]
)
It worked.
I partially coped with my issue by creating set of measures for each combination of product and country:
A_US = TOTALYTD(SUM(Sales[Sales]);'Calendar'[Date];FILTER(All(Sales);Sales[Product]="A"&&Sales[Country]="US"))
A_Canada = TOTALYTD(SUM(Sales[Sales]);'Calendar'[Date];FILTER(All(Sales);Sales[Product]="A"&&Sales[Country]="Canada"))
and so on. But what if i have 100 products and 30 countries? I think I need to create a column "Running total" in "Sales" that calculates running total for each product and aech country.
The problem of the TOTALYTD function is that it takes only one filter.
The tricks is to use the filter function like you do on the second response.
To use only one column for all product and country you have to get the context of the current row .
To achieve this you have the function earlier in dax.
Here the documentation about earlier : https://learn.microsoft.com/en-us/dax/earlier-function-dax
The column need to be build with this expression :
TOTALYTD(SUM(Sales[Sales]),'Calendar'[Date],filter(Sales,and(Sales[Country]=EARLIER(sales[Country]),sales[Product] = EARLIER(sales[Product]))))