I can't get Power BI to filter by last date in file.
When I try:
test = CALCULATE(
DISTINCT(table[Date]),
filter(
all(table[Date]),
table[Date] = date(2019,3,1)
)
)
It returns me the date March 1, 2019.
But if I use
test = CALCULATE(
DISTINCT(tabela_ajustada[Data]),
filter(
all(tabela_ajustada[Data]),
tabela_ajustada[Data] = LASTDATE(tabela_ajustada[Data])
)
)
It won't work, it's not filtering at all, so I get an error because it returns multiple values and I can't add to the card.
table[Date] has multiple non unique values.
Change to:
test =
CALCULATE(
DISTINCT(tabela_ajustada[Data]),
FILTER(
ALL(tabela_ajustada[Data]),
tabela_ajustada[Data] = LASTDATE ( ALL ( tabela_ajustada[Data] ) )
)
)
Related
I have a table with ID and with different statuses but some are not having both. I need create measure that will give the count for all the ID's that are having different statues.
I have tried below Dax functions but not giving the expected results.
Link-EC-Count =
VAR count_Donor =
CALCULATE (
DISTINCTCOUNT ( MagentaBuilt_Linked[Microwave IQ Link ID] ),
FILTER (
ALLEXCEPT ( MagentaBuilt_Linked, MagentaBuilt_Linked[Microwave IQ Link ID] ),
MagentaBuilt_Linked[Site_Nature] = "Donor"
),
FILTER (
MagentaBuilt_Linked,
MagentaBuilt_Linked[Primary AAV Vendor] = "T-Mobile"
)
)
VAR count_Recepient =
CALCULATE (
DISTINCTCOUNT ( MagentaBuilt_Linked[Microwave IQ Link ID] ),
FILTER (
ALLEXCEPT ( MagentaBuilt_Linked, MagentaBuilt_Linked[Microwave IQ Link ID] ),
MagentaBuilt_Linked[Site_Nature] = "Recipient"
),
FILTER (
MagentaBuilt_Linked,
MagentaBuilt_Linked[Primary AAV Vendor] = "T-Mobile"
)
)
RETURN
IF ( count_Donor > 0 && count_Recepient > 0, 1, 0 )
Here is the sample data looks like
Anybody have any ideas?
Here's a calculated column formula for "Eligible Row?" that works:
Eligible Row? =
IF(
CALCULATE(
COUNTROWS('Table'),
FILTER('Table',
'Table'[Affiliate ID]=EARLIER('Table'[Affiliate ID]) &&
'Table'[Achievement Type] <> EARLIER('Table'[Achievement Type])))>0,
"Yes","No")
The idea is to filter the table for rows when the Affiliate ID matches, then filter for rows where the Achievement is different, then count the rows.
Here are formulas for my two intermediate calculated columns:
Count ID =
CALCULATE(
COUNTROWS('Table'),
FILTER('Table',
'Table'[Affiliate ID]=EARLIER('Table'[Affiliate ID])))
Count Other Achievements =
CALCULATE(
COUNTROWS('Table'),
FILTER('Table',
'Table'[Affiliate ID]=EARLIER('Table'[Affiliate ID]) &&
'Table'[Achievement Type] <> EARLIER('Table'[Achievement Type])))
I think This is what you need. Try this code as measure:
Count ID =
VAR TblSummary = ADDCOLUMNS(
SUMMARIZE('Sheet 1','Sheet 1'[Affiliate Id],'Sheet 1'[Achievement Type]),
"UniqueCount",CALCULATE(COUNT('Sheet 1'[Affiliate Id]),ALLEXCEPT('Sheet 1','Sheet 1'[Affiliate Id]))
)
RETURN
SUMX(TblSummary,IF([UniqueCount]>1,[UniqueCount]))
If we test it on a visual:
I have a measure (Users_1) that calculates number of rows between specific dates that have the parameter is_sql = 0.
This measure is used in a table alongside with other measures.
I have 5 more filters on the page that that should affect this specific measure and so I can not use All(users).
One of the filters on this page is "is_sql". And when is_sql = 1 every measure except for measure (Users_1) should change to correspondig value. Measure (Users_1) shold stay the same.
Now when I chose is_sql = 1 the measure (Users_1) is blank.
Users_1 =
CALCULATE(
COUNTROWS( 'users' ),
FILTER(
KEEPFILTERS('users'),
'users'[date (days)] <= MAX( 'Calendar'[Date] )
&&'users'[date (days)] >= MIN( 'Calendar'[Date] )
&&'users'[is_SQL] = 0
)
)
You will want to avoid using KEEPFILTERS on any filters you want to allow to look outside of the filter context:
Users_1 =
CALCULATE(
COUNTROWS( 'users' ),
'users'[date (days)] <= MAX( 'Calendar'[Date] ),
'users'[date (days)] >= MIN( 'Calendar'[Date] ),
'users'[is_SQL] = 0
)
Question
What is an efficient way to create a calculated column finding the last value of my DATE column, using the ModifiedOn column, per ID? I don't want the MAX date, just the last record (even if the last record is the minimum). Also, my table is a calculated column.
Example Table
ID
DATE
ModifiedOn
A
2/4/2020
1/16/2019
A
2/5/2020
1/17/2019
B
3/2/2020
2/7/2020
B
3/3/2020
2/8/2020
B
3/1/2020
2/9/2020
Current Formula
LastRecord =
VAR Max_Date =
CALCULATE (
MAX ( 'Table1'[ModifiedOn] ),
ALLEXCEPT ( 'Table1', 'Table1'[ID] )
)
RETURN
IF (
Table1[ModifiedOn] = Max_Date,
Table1[DATE]
)
Current Results
But using the formula I get a calculated column that looks like this:
I keep getting blanks where they should be filled with the LAST recorded date of that ID.
Use the following dax formula to create the expected column:
Column =
VAR __id = 'Table'[ID]
VAR __lastMod =
CALCULATE(
MAX( 'Table'[ModifiedOn] ),
FILTER( 'Table', 'Table'[ID] = __id )
)
VAR __lastDate =
CALCULATE(
MAX( 'Table'[Date] ),
FILTER( 'Table', 'Table'[ID] = __id && 'Table'[ModifiedOn] = __lastMod )
)
Return __lastDate
I am trying to create new measures that will only show the data value of the Last day every month and another measure will show the data value of every week Saturday in Power BI.
Many thanks in Advance.
The data is continuing and the next series of data will appended data wise
Output:
Need to create a measure which will show only last day of the Week value ( Example- Saturday is my Last of the Week and Count numbers I need to see as output)
Similarly for Month - Last day of the Month I need to see the Numbers of each service.
Do you have Calendar table mark as "Date Table", which is connected by relationship to your Table? If so, then you can use ENDOFMONTH ( 'Calendar'[issue_date] ) to get lastDateOfMonth
then simply:
ShowValueAtLastDayOfMonth =
calculate( sum(Table[Total sale]),
KEEPFILTERS(
filter(ALL('Calendar'[issue_date]),
'Calendar'[issue_date] = ENDOFMONTH ( 'Calendar'[issue_date] )
)
)
)
ShowOnlyOnSaturday =
calculate(sum(Table[Total sale]), KEEPFILTERS( FLITER(ALL('Calendar[issue_date]),
WEEKDAY ( SELECTEDVALUE('Calendar'[issue_date])) = 7 )))
Without a "Date Table" we need to replace 'Calendar'[issue_date] with your Table[Date] and ENDOFMONTH with:
VAR LastDateVisible =
CALCULATE ( MAX ( 'Table'[Date] ) )
VAR LastYearVisible =
YEAR ( LastDateVisible )
VAR LastMonthVisible =
MONTH ( LastDateVisible )
VAR DaysInMonth =
FILTER (
ALL ( 'Table'[Date] ),
YEAR ( 'Table'[Date] ) = LastYearVisible
&& MONTH ( 'Table'[Date] ) = LastMonthVisible
)
VAR LastDayInMonth =
MAXX (
DaysInMonth,
'Table'[Date]
)
VAR Result =
CALCULATETABLE (
VALUES ( 'Table'[Date] ),
'Table'[Date] = LastDayInMonth
)
RETURN
Result
I need to summarize dax table and filter it by date range 5 month back from last EffectiveDate, which is 7/27/2019
So my dax expression:
TestTable1 =
VAR LastEffDate = LASTDATE(fact_Premium[EffectiveDate]) // -- 7/27/2019
RETURN
SUMMARIZE(
FILTER(dim_Date, DATEDIFF(DATEADD(STARTOFMONTH(LastEffDate), -5,MONTH), ENDOFMONTH(LastEffDate), MONTH)),
dim_Date[Year Month],
"Premium", [Ttl WP]
)
But for some reason it brings me data for all years in a dataset:
I also tried:
TestTable1 =
VAR LastEffDate = LASTDATE(fact_Premium[EffectiveDate]) // -- 7/27/2019
RETURN
SUMMARIZE (
FILTER (
dim_Date,
DATESBETWEEN(dim_Date[Date],
DATE(2019,5,1),
DATE(2019,6,1)
)
),
dim_Date[Year Month],
"Premium", [Ttl WP]
)
But it gives me an error:
A table of multiple values was supplied where a single value was expected.
Am I missing something here?
Your filter expression should be using DATESBETWEEN and not the datediff:
TestTable1 =
VAR LastEffDate = LASTDATE(fact_Premium[EffectiveDate]) // -- 7/27/2019
RETURN
SUMMARIZE (
FILTER (
dim_Date,
DATESBETWEEN(
//expression for start date,
//expression for end date
)
),
dim_Date[Year Month],
"Premium", [Ttl WP]
)
I think you are still missing aggregating your Premium,
SUM(Ttl WP)
TestTable1 =
VAR LastEffDate =
LASTDATE ( fact_Premium[EffectiveDate] ) // -- 7/27/2019
RETURN
SUMMARIZE (
FILTER (
dim_Date,
DATESBETWEEN ( dim_Date[Date], DATE ( 2019, 5, 1 ), DATE ( 2019, 6, 1 ) )
),
dim_Date[Year Month],
"Premium", SUM ( [Ttl WP] ) ---- Need to aggregate here
)