PowerBI RANKX is not continious - powerbi

I want to show the TOP10 difference in a measure.
The difference is calculated YTD actual + Rest of the year forecast - Full year budget values.
The normal measure looks like this:
VAR _Year =
SELECTEDVALUE ( 'Calendar'[Year] )
RETURN
(
CALCULATE (
SELECTEDMEASURE (),
DATESYTD ( Calendar[Dates] ),
CRDB[Scenario] = "Actual",
ALL ( CRDB[ForecastTypeFinal] )
)
+ CALCULATE (
SELECTEDMEASURE (),
CRDB[Scenario] = "Forecast",
'Calendar'[Dates] >= DATE ( _Year, 1, 1 )
&& 'Calendar'[Dates] <= DATE ( _Year, 12, 31 )
)
)
- CALCULATE (
SELECTEDMEASURE (),
Calendar[Dates] >= DATE ( _Year, 1, 1 )
&& Calendar[Dates] <= DATE ( _Year, 12, 31 ),
CRDB[Scenario] = "Budget",
ALL ( CRDB[ForecastTypeFinal] )
)
I would like to rank by project, so I made this ranking measure:
RANKX (
ALL ( CRDB[Project ID - Project ID Level 01 (Text)] ),
(
CALCULATE (
SELECTEDMEASURE (),
DATESYTD ( Calendar[Dates] ),
CRDB[Scenario] = "Actual",
ALL ( CRDB[ForecastTypeFinal] )
)
+ CALCULATE (
SELECTEDMEASURE (),
CRDB[Scenario] = "Forecast",
'Calendar'[Dates] >= DATE ( SELECTEDVALUE ( 'Calendar'[Year] ), 1, 1 )
&& 'Calendar'[Dates] <= DATE ( SELECTEDVALUE ( 'Calendar'[Year] ), 12, 31 )
)
)
- CALCULATE (
SELECTEDMEASURE (),
Calendar[Dates] >= DATE ( SELECTEDVALUE ( 'Calendar'[Year] ), 1, 1 )
&& Calendar[Dates] <= DATE ( SELECTEDVALUE ( 'Calendar'[Year] ), 12, 31 ),
CRDB[Scenario] = "Budget",
ALL ( CRDB[ForecastTypeFinal] )
),
,
DESC
))
The ranking gets me the correct projects, but when I look at the rank values, they are not right:
ranking values
The values are not the same, so it is no reason for skipping places.
What do I do wrong?
Thank you for your help in advance.

Related

EARLIER Function not working in DAX - ATR of Stocks

I am making ATR34 column in PowerBI in which I have a table that consists of Stocks, Date, High, Low, Close, PrevClose and Series (contains Equity,future).
I have made a calculated column of ATR from the High Low Close and Prev Close. I need to calculate the MA of 34 days of ATR calculated filtered by Stocks and Equity.
For that I am first calculating the Daynumber filtering Stocks and EQ; then 34 days and making an average of it.
However when i am using the below mentioned code in DAX EARLIER function is not working and i am unable to calculate it.
I am beginner in POWERBI.
DayNumber =
COUNTROWS (
FILTER ('Table','Table'[Date] <= EARLIER ( 'Table'[Date] )),
FILTER('Table'[Stock] = EARLIER ( 'Table'[Stock] )),
FILTER('Table'[EQ] = EARLIER ( 'Table'[EQ] ))
)
Another Caulcated Measured Column :
FirstDateOfRange34 =
CALCULATE (
VALUES ( 'Table'[Date] ),
FILTER ( 'Table','Table'[DayNumber] = EARLIER ( 'Table'[DayNumber] ) - 34),
FILTER('Table'[Stock] = EARLIER ( 'Table'[Stock] )),
FILTER('Table'[EQ] = EARLIER ( 'Table'[EQ] ))
)
Another Calculated Measured Column :
ATR34 =
CALCULATE (
AVERAGE ( 'Table'[ATR] ),
FILTER ( 'Table','Table'[Date] >= EARLIER ( 'Table'[FirstDateOfRange34] ))
FILTER ('Table','Table'[Date] <= EARLIER ( 'Table'[Date] ))
FILTER('Table'[Stock] = EARLIER ( 'Table'[Stock] ))
FILTER('Table'[EQ] = EARLIER ( 'Table'[EQ] ))
)
Your syntax is off. COUNTROWS expects a single table argument, not three arguments and FILTER needs a table for the first argument, not a column.
Try this intead:
DayNumber =
COUNTROWS (
FILTER (
'Table',
'Table'[Date] <= EARLIER ( 'Table'[Date] )
&& 'Table'[Stock] = EARLIER ( 'Table'[Stock] )
&& 'Table'[EQ] = EARLIER ( 'Table'[EQ] )
)
FirstDateOfRange34 =
CALCULATE (
VALUES ( 'Table'[Date] ),
FILTER (
'Table',
'Table'[DayNumber] = EARLIER ( 'Table'[DayNumber] ) - 34
&& 'Table'[Stock] = EARLIER ( 'Table'[Stock] )
&& 'Table'[EQ] = EARLIER ( 'Table'[EQ] )
)
)
ATR34 =
CALCULATE (
AVERAGE ( 'Table'[ATR] ),
FILTER (
'Table',
'Table'[Date] >= EARLIER ( 'Table'[FirstDateOfRange34] )
&& 'Table'[Date] <= EARLIER ( 'Table'[Date] )
&& 'Table'[Stock] = EARLIER ( 'Table'[Stock] )
&& 'Table'[EQ] = EARLIER ( 'Table'[EQ] )
)
)

Countrows/calculate/sum rows in DAX

I am fairly new with Power BI and DAX and I'm stuck. I'll try to explain the current situation and what I want to become my output. I've tried a lot of meaures with distinctcount, calculate, you name it, I did it. But can't find the right solution.
We've got 4 columns: Date, Employee_ID, Sick, %FTE. Every row records if an employee was sick on that date. Blank is not sick and Y = sick.
I would like to create a measure where it counts the %FTE just once when an employee is sick in a particular week, month or year.
So the output of January should be 2,13 (0,8 + 0,33 + 1) and in February 1,8 (0,8 + 1).
enter image description here
You would need two additional columns in the dataset as following
Once you have that, you can use the following measures to reach the goal
Measure8 =
VAR _1 =
IF (
MAX ( 'fact'[sick] ) <> BLANK (),
RANKX (
FILTER (
ALL ( 'fact' ),
'fact'[emp_id] = MAX ( 'fact'[emp_id] )
&& 'fact'[Year] = MAX ( 'fact'[Year] )
&& 'fact'[Month] = MAX ( 'fact'[Month] )
&& 'fact'[sick] = "Y"
),
CALCULATE ( MAX ( 'fact'[date] ) ),
,
ASC,
DENSE
)
)
VAR _2 =
IF ( _1 = 1, IF ( MAX ( 'fact'[sick] ) = "y", MAX ( 'fact'[%FTE] ) ) )
RETURN
_2
Measure9 =
IF (
HASONEVALUE ( 'date'[date] ),
[Measure8],
VAR _1 =
MAXX (
GROUPBY (
ADDCOLUMNS ( 'fact', "val", [Measure8] ),
[Year],
[Month],
"total", SUMX ( CURRENTGROUP (), [val] )
),
[total]
)
VAR _2 =
MAXX (
GROUPBY (
ADDCOLUMNS ( 'fact', "val", [Measure8] ),
[Year],
"total", SUMX ( CURRENTGROUP (), [val] )
),
[total]
)
VAR _3 =
IF ( ISINSCOPE ( 'fact'[Year] ), _2, _1 )
RETURN
_3
)
Also, for any future posts please provide the sample data and expected output as markdown tables How To

Power BI Dax Group By Measure - Display Dates Before Today

I am trying to create a measure that will show booked revenue over time, grouped by a few categories. I also want to show as 0 within line charts when the data is BLANK(), so I have it in an IF statement. Everything works just fine except for whatever reason I cannot get it to only show dates prior to today.
Here is the current Measure:
M_BookedRevenue =
VAR CurrentAccountingYear =
CALCULATE ( MIN ( 'Date'[AccountingYear] ), 'Date'[Date] = TODAY () )
VAR CurrentDate =
CALCULATE ( MIN ( 'Date'[SortDate] ), 'Date'[Date] = TODAY() )
RETURN
CALCULATE (
IF (
ISBLANK (
SUMX (
FILTER (
GROUPBY (
RevenueChannel,
RevenueChannel[ChannelBucket],
RevenueChannel[Channel],
'Date'[Date],
'Date'[SortDate],
'Date'[AccountingWeek],
'Date'[WeekNumber],
'Date'[AccountingMonthEnglishAbbrYear],
'Date'[AccountingMonth],
'Date'[AccountingYear],
"Revenue", SUMX ( CURRENTGROUP (), RevenueChannel[TransactionRevenue] )
),
'Date'[AccountingYear] >= CurrentAccountingYear
&& 'Date'[SortDate] < CurrentDate
),
[Revenue]
)
),
0,
SUMX (
FILTER (
GROUPBY (
RevenueChannel,
RevenueChannel[ChannelBucket],
RevenueChannel[Channel],
'Date'[Date],
'Date'[SortDate],
'Date'[AccountingWeek],
'Date'[WeekNumber],
'Date'[AccountingMonthEnglishAbbrYear],
'Date'[AccountingMonth],
'Date'[AccountingYear],
"Revenue", SUMX ( CURRENTGROUP (), RevenueChannel[TransactionRevenue] )
),
'Date'[AccountingYear] >= CurrentAccountingYear
&& 'Date'[SortDate] < CurrentDate
),
[Revenue]
)
)
)

How to get a column total using SUMX and table expression in Power BI

I have a table expression inside the SUMX() function.
How can I get a total of column "Open" in my scenario?
TestMeasure =
SUMX (
ADDCOLUMNS (
SUMMARIZE (
FILTER (
SumByClaim,
SumByClaim[TransactionDate] >= FIRSTDATE ( SumByClaim[TransactionDate] )
&& SumByClaim[TransactionDate] <= LASTDATE ( SumByClaim[TransactionDate] )
),
SumByClaim[ClaimNumber],
SumByClaim[ClaimantID],
SumByClaim[ClaimStatus],
"MaxTransDate", MAX ( SumByClaim[TransactionDate] )
),
"Open", IF (
SumByClaim[ClaimStatus] = "Open"
&& [MaxTransDate] = MAX ( SumByClaim[TransactionDate] ),
1,
0
)
),
[Open]
)
UPDATE: Thanks #CR7SMS.
But now it looks a little high:
I tried:
TestMeasure3 =
SUMX(SumByClaim,
SUMX (
ADDCOLUMNS (
SUMMARIZE (
FILTER (
SumByClaim,
SumByClaim[TransactionDate] >= FIRSTDATE ( SumByClaim[TransactionDate] )
&& SumByClaim[TransactionDate] <= LASTDATE ( SumByClaim[TransactionDate] )
),
SumByClaim[ClaimNumber],
SumByClaim[ClaimantID],
SumByClaim[ClaimStatus],
"MaxTransDate", MAX ( SumByClaim[TransactionDate] )
),
"Open", IF (
SumByClaim[ClaimStatus] = "Open"
&& [MaxTransDate] = MAX ( SumByClaim[TransactionDate] ),
1,
0
)
),
[Open]
)
)
I added SUMX over the calculation and it is giving me a higher total. I am not sure if the results are what you are looking for but you can give it a try:
TestMeasure =
SUMX(SumByClaim,SUMX (
ADDCOLUMNS (
SUMMARIZE (
FILTER (
SumByClaim,
SumByClaim[TransactionDate] >= FIRSTDATE ( SumByClaim[TransactionDate] )
&& SumByClaim[TransactionDate] <= LASTDATE ( SumByClaim[TransactionDate] )
),
SumByClaim[ClaimNumber],
SumByClaim[ClaimantID],
SumByClaim[ClaimStatus],
"MaxTransDate", MAX ( SumByClaim[TransactionDate] )
),
"Open", IF (
SumByClaim[ClaimStatus] = "Open"
&& [MaxTransDate] = MAX ( SumByClaim[TransactionDate] ),
1,
0
)
),
[Open]
))

Calculation based on previous row in same column and previous row in another column in power bi

I am trying to calculate NoofEventsInQueue Column as below in power Bi. 157 is the total no of Events
In a calculated column:
NumberOfEventsInQueue =
IF (
ISBLANK ( Table1[NoOfEventsAtATime] ),
BLANK(),
CALCULATE (
SUM ( Table1[NoOfEventsAtATime] ),
FILTER (
ALL ( Table1 ),
Table1[Ref_Time] >= EARLIER ( Table1[Ref_Time] )
)
)
)
If you have blank rows in the middle of your NoOfEventsAtATime column, and still want a value returned on your calculated column, you could use something like:
NumberOfEventsInQueue =
VAR TimeMin =
CALCULATE (
MIN ( Table1[Ref_Time] ),
FILTER (
ALL ( Table1 ),
NOT ISBLANK ( Table1[NoOfEventsAtATime] )
)
)
VAR TimeMax =
CALCULATE (
MAX ( Table1[Ref_Time] ),
FILTER (
ALL ( Table1 ),
NOT ISBLANK ( Table1[NoOfEventsAtATime] )
)
)
VAR Output =
IF (
Table1[Ref_Time] >= TimeMin && Table1[Ref_Time] <= TimeMax,
CALCULATE (
SUM ( Table1[NoOfEventsAtATime] ),
FILTER (
ALL ( Table1 ),
Table1[Ref_Time] >= EARLIER ( Table1[Ref_Time] )
)
),
BLANK()
)
RETURN Output