Month slicer and filter not working properly on rolling data Power BI - dax

i All.
I have created below measure to reflects always 3 month figures when month slicer is used.
3R =
CALCULATE(COUNT('Order'[Order/ not ordered]),DATESINPERIOD('Date'[Date],LASTDATE('Date'[Date]),-3,MONTH)))
However, when I try to add salesman figures as filter with below formula, and click to month slicer it is directly show just choosen month figures not 3 months.
3R John =
CALCULATE(COUNT('Order'[Order/ notordered])
,DATESINPERIOD('Date'[Date],LASTDATE('Date'[Date]),-3,MONTH),FILTER('Order','Order'[Salesman]="John")))
on below link I have shared a sample for this. there are 2 different table and 1 matrix.
Matrix is named working and 1 of the table is named as "not working properly". not selecting any value on slicer. all data gives same data. however when clicked month slicer not named main table is changing and this is correct. also matrix is correct but table that I am trying to achive is not working.
What i am trying to achive is, 3 month roling data based on customer and salesman. when click for example 1 on month slicer table should give January 2020, December 2019 and November 2019 figures.
https://drive.google.com/file/d/1LoqSiKhHMFn_OioI2RnXOzjcIL9dPRjS/view?usp=sharing

below is the solution. worked for me.
3R John =CALCULATE(COUNT('Order'[Order/notordered]),DATESINPERIOD('Date'[Date],LASTDATE('Date'[Date]),-3,MONTH),'Order'[Salesman]="John"))
just remove filter('order', section and it is ok now.

Related

Microsoft Power BI, DAX - tricky ALLSELECTED with 2 values in slicer, but show only TOP 1 row in visual

This question is an extension of an already answered question, which I posted this week.
I have the below situation in Microsoft Power BI.
I have 2 simple tables:
1) CountryTable
2) YearTable
There is a 1-M relationship between YearTable and CountryTable.
The latter (YearTable) is used to feed values into a slicer.
(In my client database, Year has some alphabetical prefixes, such as Q1-2022, so I prefer to use YearOrder column to sort the Year column at the backend, while the slicer will display the Year column.)
The former (CountryTable) is the main table, with just a few sample rows.
These two tables are related via the Year column.
The Year slicer always has EXACTLY 2 values chosen in my Power BI report.
I need the Maximum of these two values of the year slicer as a measure, for each row of my visual.
At the same time, these two year values of the slicer must remove the unwanted rows in my report visual, based on the slicer selection of year values.
For example, when the slicer has 2019 and 2020 chosen, I need the value as in the DesiredOutput1 page.
Similarly, you can see DesiredOutput2 (Slicer values are 2020 and 2022); DesiredOutput3 (Slicer values are 2019 and 2022) pages.
I have indeed successfully obtained DesiredOutput1, DesiredOutput2, DesiredOutput3. Thanks to all the folks who helped me attain this.
Now, my main requirement in this posting, is this:
After obtaining the DesiredOutputs above, I need the following output:
Show only the TOP 1 row (ASC order of Year column, which is the minimum value of the slicer).
Essentially:
Year column of the visual: Minimum value of the slicer
MaxYear_Measure_SlicerSelection: Maximum value of the slicer (maximum of the two values chosen in the slicer)
You can see below:
Note: MaxYear_Measure_SlicerSelection measure can refer to any one of the two measures [MaxYear] or [MaxYearMeasure_Community] (see the .pbix file for the formulas of the measures).
Any idea ?
I prefer the Year column of the visual not to be converted to a new measure. Would RANKX help in this case ? Any thoughts?

SUMIFS Between Conditions

I am looking for some help with a SUMIFS formula.
I am trying calculate the revenue between dates for a coupon code, where the coupon code sales are in a separate sheet. I need the between dates to be until that discount code appears in the sheet again.
For example,
If a discount code is promoted on the 25th of January and again on the 30th of January, I need the 25th of January row to show the sales since then until the SAME code is promoted again (eg. between 25th January and between 30th January). The 30th of January row would then show the revenue from that date onwards, until the code appears again in another date row in the future.
This is my formula:
=SUMIFS('Code Revenue Feed'!$E:$E,'Code Revenue Feed'!$C:$C,D2,'Code Revenue Feed'!$A:$A,">=" &$B2)
This formula does not show between dates, only from the date it is promoted but I need to show from that date, until the next date the code appears again.
Here's my dataset (please filter the code column by KATIEHAYES so you can see what I mean):
https://docs.google.com/spreadsheets/d/1kzU6T6a95WPoCDkkMjDmqWkKTDOxA0whn1Zk5kGRbBQ/edit?usp=sharing
For this to work, you need to enter an end date in column C (in my copy of your data, this is in cell C664 of the Posting Details UK sheet) where I have chosen 31-Dec-2022 (as your file is view-only, and because you appear to have a filter active on the Posting Details UK sheet, when I copied your data the last row of data on my sheet is 663)
=SUMIFS('Code Revenue Feed'!$E$3:$E$5180,'Code Revenue Feed'!$C$3:$C$5180,D2,'Code Revenue Feed'!$A$3:$A$5180,">="&C2,'Code Revenue Feed'!$A$3:$A$5180,"<"&INDIRECT("C"&IFNA(match(D2,D3:D$663,0)+ROW(),664)))
the above formula can be entered in cell E2 of your UK sheet, and then copied down. This formula uses the INDIRECT() function to determine the 'until' date - if a match for the current coupon code cannot be found in the remaining rows, then the end date from row 664 is used (you will have to adjust both the 663 and 664 references as you have almost 200 more rows of data).

How do I subtract two rows from a POWERBI custom table?

Project
Cost
January
323
Feb
323
I have a table as followed seen above which ROW is month (filtered by a certain project) and values are cost of the project. I want to calcuate the difference between two months, but I am having trouble.
How do I subtract two rows from each other.
In the code I wrote:
Variance = [Cost] - CALCULATE([Cost],PREVIOUSMONTH('Month'[Month))
I get the following error, A column specified in the call to function is not of type date.
Is there a way to manual subtract two months?
The best way to do it is to replace your month with an actual Date value. The first of the month for example. The you should be able to do something like this assuming your month dates are unique: If they are not unique you should create a Dates table (See Microsoft's Guidance on date table) and join.
variance = [Cost] - Calculate([COST],(PARALLELPERIOD(Month[Month],-1,Month)
You can use EARLIER function here but, only when the Months have an Id. Such as
1 Jan
2 Feb
3 March
...
Link for details
However, I would suggest creating a date table and then having a relationship from the date table to your table. By using date table you can easily achieve using in-buit date functions.

Power Query - DATEADD fails once current year filter applies

Please help. I don't understand why I have 2 similar data models and one works but the other does not.
I have a fact table with a Calendar Key and data as granular by day by location. I have a calendar dimension table with a Calendar key, each individual date, and month/fiscal year definitions.
Measures are Rev = SUM(FactTable[RevColumn]) then Rev PY = CALCULATE([Rev], DATEADD(CalendarTable[Day_Date], -1, YEAR))
Model 1 in Power BI, when I apply date filters, Rev calculates the total revenue & Rev PY calculates last year's rev for same range. Even if I select all dates that are YTD (which is tedious)
Model 2 in Excel 2016 Power Query, when I apply a year filter, Rev calculates total revenue for YTD in Fiscal Year & Rev PY is blank.
I don't understand what is different and why it would even fail in the first place. Calculate is supposed to override the filter context of the current filters right?
Also: the only "Date" type columns are located in the calendar table so it's not possible for me to select the wrong table.
I ultimately had to ask a professor on Udemy.com. The solution is to mark you calendar dimension table as a "Date Table." Since I'm combining the 2 tables on a whole number field, the time intelligence functions only work when filtering with date columns.
By marking the Calendar table as the Date table, the time intelligence functions know to use any attributes from that table to filter down the date ranges and get and display the appropriate answer.
In Power Pivot view, click the "Design" ribbon, then click the "Date Table" button and the "Set Default" button after that.
This resolved all issues I had.

Visual Studio Report Designer: I don't understand group filters

I'm writing a report that has proposal information by estimator per month. So I created a matrix where each row is grouped by estimator and each column is grouped by the month.
The thing is, my query includes data for this year AND last year, but the columns by month should only contain this year's information. So I though simple, I'll create a filter: Year(variable_date) = Year(Today()).
When I do this, no record information shows up. But then I changed the column to group by month AND year and suddenly, it works. Only 2015 records show up in the calculations per month.
Why did I need to group it by month AND year? Why couldn't I just group by month and have the filter remove records that didn't have the correct year using the filter group property tab?
Thanks!
P.S. I hope I have the tags right...
It sounds like month and year are separate fields. So when you group only by month it is grouping all of the rows where the value for that field is the same. (Month=8 exists in 2014 and 2015.) The values are just numbers to SSRS and it doesn't know it needs to look at the year field too unless you tell it to.

Resources