I´m really struggling about the following problem, searched a lot, tried a lot but still I´m not able to achieve my goal. I really hope, that someone can help me out with this.
Situation
I´ve created a meassure:
Measure =
VAR selYear = SELECTEDVALUE('Stats Param LindyCalendar'[Date].[Year])
VAR selMonth = SELECTEDVALUE('Stats Param LindyCalendar'[Month])
VAR selDay = day(now())
VAR enddate = DATE(selYear, selMonth, selDay)
VAR CurWorkingDay =
COUNTROWS(
FILTER(
FILTER('Stats Param LindyCalendar', 'Stats Param LindyCalendar'[Date].[Date] <= enddate),
'Stats Param LindyCalendar'[WorkingDay_YN] = -1))
RETURN CurWorkingDay
There are three slicers. The first one is based on Country-Table which has correct working relationships to all needed tables. It just filters the Country.
The second slicer is based on 'Stats Param LindyCalendar'[Date].[Year].
The last one is based on 'Stats Param LindyCalendar'[Date].[Month].
When I play around with the slicer, setting random values, it works fine.
Goal:
I want to get back the CurWorkingDay of the last year.
So I did:
VAR selYear = SELECTEDVALUE('Stats Param LindyCalendar'[Date].[Year])-1
The result is "Blank" in the Card-Visual.
That´s my problem, and I don´t know how to fix that.
Would be great if someone could provide a solution or hint.
Thanks a lot in advance.
Finally I got it.
workingdays_MTD =
VAR selYear = SELECTEDVALUE('Stats Param LindyCalendar'[Date].[Year])-1
VAR selMonth = SELECTEDVALUE('Stats Param LindyCalendar'[Month])
VAR selDay = day(now())
VAR enddate = DATE(selYear, selMonth, selDay)
VAR test =
TOTALMTD(COUNTROWS('Stats Param LindyCalendar'),'Stats Param LindyCalendar'[Date].[Date] = enddate,'Stats Param LindyCalendar'[WorkingDay_YN] =-1)
RETURN test
Power BI marks an error for "'Stats Param LindyCalendar'[Date].[Date] = enddate," but it works anyway...
Related
I have the following two DAX Commands, who seem to be giving different results,
First DAX command
FourLeggedSales = SUMX(
FILTER(Purchase, RELATED('Product'[Legs]) = 4),
Purchase[Quantity]
)
Second DAX Command,
FourLeggedSales = CALCULATE( SUM(Purchase[Quantity]), 'Product'[Legs] = 4)
The second DAX Command is given in the solution file and apparently gives correct results. While the first one was what I wrote and it is giving wrong results.
Can anyone help me understand what's causing the issue here?
Additional Information if Needed
Just to be clear, I am solving this problem of DAX here: https://www.wiseowl.co.uk/power-bi/exercises/dax/filtering/4094/
You can find the Example Workbook from the link provided as well (with the dataset)
^These are the two example DAX Commands I gave here.
Complete DAX Measure that I created is as given (it doesn't give correct results)
Ratio =
var FourLeggedSales = SUMX(
FILTER(Purchase, RELATED('Product'[Legs]) = 4),
Purchase[Quantity]
)
var SixLeggedSales = SUMX(
FILTER(Purchase, RELATED('Product'[Legs]) = 6),
Purchase[Quantity]
)
var SumOfSales = FourLeggedSales + SixLeggedSales
var ManyLeggedRatio = DIVIDE(SUMX(Purchase,Purchase[Quantity]), SumOfSales, 0)
Return ManyLeggedRatio
The result of the measure I created is as given,
The Measure created in the Solution File is as below,
FourLeggedRatio =
VAR SalesFourLegs = CALCULATE( SUM(Purchase[Quantity]), 'Product'[Legs] = 4)
VAR SalesSixLegs = CALCULATE( SUM(Purchase[Quantity]), 'Product'[Legs] = 6)
VAR ManyLeggedRatio = DIVIDE(SUM(Purchase[Quantity]) , (SalesFourLegs + SalesSixLegs))
RETURN ManyLeggedRatio
Result of the Measure in the Solution File is as given,
I'm hoping for some help with my measures. My data is quite sensitive so it's not easy to share. I've attempted to mock up as sales so hope it makes sense.
https://1drv.ms/u/s!Ap6q8W-mvm27g-dWehgkV6-p33VVsA?e=bGj3nV
I have written a measure to count the number of resales by TransactionID. I then use a sumx to total the resales by Transaction ID.
I've added this measure to a matrix against Month for Banding and this shows the correct row and column totals.
In the FACT Salestable, I have a field 'Tier'. When I attempt to add 'Tier' to a stacked column chart using the same measures, the data is incorrect. I think it is because the sumx is losing the filter created in the first measure but I don't really understand how to rectify this and have been trying for days!
Is anyone able to identify where my measures are incorrect - Id like to try to understand what exactly I'm asking the measure to do so I know where I'm going wrong for future work! Any help would be very much appreciated - thank you!
MEASURE 1:
CountResales =
Var _Cust = Max (FACTSales[CustomerID])
Var _Date = CALCULATE(min(FACTSales[DateOrigSale]),ALLSELECTED(FACTSales),FACTSales[CustomerID]=_Cust)
Var _ID = CALCULATE(min(FACTSales[CohortID]),ALLSELECTED(FACTSales),FACTSales[CustomerID]=_Cust,FACTSales[DateOrigSale]=_Date)
Var _CountResales =
CALCULATE(DISTINCTCOUNT('DIMReSales transactions'[TransactionID]),
VALUES('DIMReSales transactions'[TransactionID]),'DIMReSales transactions'[CohortID]=_ID,
'DIMReSales transactions'[New Sale]=1)
Return
_CountResales
MEASURE 2:
SumResales = Sumx(values('FACTSales'),[CountResales])
I am very new to the PowerBI community and I am confused about how to visualize and create measures/columns for the data which requires comparing last week/month/year data with respect to the current week.
I have tried various solutions available on the internet or other forums. I would appreciate it if anyone can please outline the steps required to achieve the goal.
The data that I have is transactional data and I have also created a Date Table. I am not sure how to go ahead with the problem.
You can create measures like this (for days):
PreviousDay =
var __DayOnRow = SELECTEDVALUE(Calendar[day])
return
CALCULATE( SUM(Table[SomethingToSum]), FILTER(ALL(Calendar),Calendar[day] = __DayOnRow -1 ))
How this work:
SELECTEDVALUE gets a specific day from the current context
__DayOnRow -1 give us a previous Day (not yesterday date< except for today date>)
FILTER with ALL, remove every filter on Calendar (current row is also a filter, so without removing filter we get two excluding conditions )
How do that for WEEK?
PreviousWeek =
var __WeekOnRow = SELECTEDVALUE(Calendar[Week])
var __FirstDayOfWeek = calculate(min(Calendar[Day]), FILTER(ALL(Calendar), __WeekOnRow = Calendar[Week] ))
var __LastDayOfWeek = calculate(max(Calendar[Day]), FILTER(ALL(Calendar), __WeekOnRow = Calendar[Week] ))
return
CALCULATE(SUM(Table[SomethingToSum]), FILTER(ALL(Calendar),Calendar[day] >= __FirstDayOfWeek -7 && Calendar[day] <= __LastDayOfWeek -7 ))
Hello I would need someones help please.
I want to combine two different tasks and don't know how.
First I created an row number for each group: Description for Task1
I grouped the table by a station ID.
Now I want to get the value from the previous row: Description for Task2
The problem is that this doesn't work:
I think this comes due to the fakt that the index is not unique.
Because for example the index "1" exists for every ID.
Maybe it's easier to understand when u see the table. I blacked out specific values because they are not important for this.
I would need to only take the index+1 where the index+1 and index have the same ID.
What I want to achive is to get a column which shows me the previous value from beschreibung. But only the previuos value where the ID is the same.
Does anyone know how to solve this?
My guess is that you need to do the lookupvalue task in powerquery. But I don't know how.
Maybe something like this? : Lookup Value
I welcome any help.
Based on your update:
MeasurePrev = var __lastInd = CALCULATE(MAX('Table'[Beschreibung]), FILTER(ALL('Table'), 'Table'[index] = SELECTEDVALUE('Table'[index]) +1 ), VALUES('Table'[ID]))
return __lastInd
CalculatedColumnPrev = var _idx = 'Table'[index] +1
var _NodeId = 'Table'[ID]
return
CALCULATE(max('Table'[Beschreibung]), FILTER(ALL('Table'), ('Table'[index]) = _idx && 'Table'[ID] = _NodeId) )
I'm new in this so please pardon me for such a basic question.
I'm trying to pass some dates as filters to a measure.
I have a simple measure that counts opened items "last week".
The DAX I used:
OpenedLastWeek = CALCULATE(COUNTROWS(Table);Table[Created
Year]=2018;Table[Created Week]=45)
But there should be a way to pass values to the DAX code to replace manually entered "2018" and "45".
I tried Date Tables, extra tables with dates in it... I'm just confused.
Thanks.
In this case, I would probably use variables.
OpenedLastWeek =
VAR CreatedYear = --<Desired Year Calculation>--
VAR CreatedWeek = --<Desired Week Calculation>--
RETURN
CALCULATE(
COUNTROWS(Table);
Table[Created Year] = CreatedYear;
Table[Created Week] = CreatedWeek
)
Basically, you define the week and year how you'd like and then pass those variables into the CALCULATE function.
Thank you very much. It solved my problem.
For this case, I tried variables before but I was getting wrong results. I guess that was because I was using "CountA()" instead of "Countrows()".
Thanks again.
Have a nice day,
Eld