I am trying to create a slicer in PowerBI that will dynamically change the FULL_DATE whenever the ListIDrop value changes. I have a unique ID with a date range that you can see here with the code below:
ListIDrop =
VAR ListID = 'Master Table'[List ID ]
VAR Start_Date = 'Master Table'[Start Date].[Date]
VAR End_Date = 'Master Table'[End Date].[Date]
RETURN ListID & " (" & FORMAT(Start_Date, "Short Date")&" - "&FORMAT(End_Date, "Short Date") & ")"
The FULL_DATE is a slicer that will allow the user to custom search between the dates. But I want the FULL_DATE slicer to change to the dates of the ListIDrop if the ListIDrop slicer changes.
This is the behavior I see. In this example, the FULL_DATE slicer should have 4/25/2022 - 5/1/2022 selected as the range.
Any help would be appreciated. Thank you!
Related
I'm trying to filter values from a Column chart :
The chart is like this :
The lightgreen column chart value is from a Measure : Selection Date
And I use a Slicer to filter values like this :
The values are from a table Parametres
So here is my Selection_Date measure :
Selection Date = [DateFilter]
DateFilter is an other measure that choose how to filter the values (based on the slicer's selection).
DateFilter =
var _today = TODAY()
var _month = MONTH(_today)
var _year = YEAR(_today)
var _last_30_days = _today - 30
return SWITCH(SELECTEDVALUE(Parametres[Selection_date]),
"Last30Days", CALCULATE( SUM(v_revenues[qty]), FILTER(v_dates, v_dates[Date] > _last_30_days )),
"MonthToDate", CALCULATE(SUM(v_revenues[qty]), FILTER(v_dates, v_dates[actual_month] = 1)),
"YearToDate", CALCULATE(SUM(v_revenues[qty]), FILTER(v_dates, v_dates[actual_year] = 1))
)
This measure works but I still have one problem. The filter is ok but when I filter a values (example month to date) all the value that are not in the selection (all the values that are not november 2021) are still visible but they are empty :
So here is my question :
How can I add the values that are not in the selection ? How can I filter so it only display the values that are in the checked in the slicer ?
Per example, for Date to Month I want only this to be displayed :
I resolved it by using a Bookmark and then I associated a button to this Bookmark !
I wanna filter a Date using a table parameters.
First, I created a Parameters table like this :
Here is the table's values :
And then I created a Slicer with the table parameters values as a list :
So what I want is to filter my Date table based on which value is selected on the slicer.
The Date table looks like this :
v_DATE
Date
Date is a "date" type.
Here are some sample values :
Date
13.10.21
14.10.21
15.10.21
The Date table is used on a bar chart with values that came from an article table.
So what I want is when I click on the Last30Days it filters me all the values from the current date to 30 days ago.
I tried this :
On my Date column, I right clicked and clicked on "New measure".
Then I wrote a DAX code like this :
Measure = CALCULATE(IF(SELECTEDVALUE(Parametres[Selection_date]) = "Last30Days", filter(v_Date, v_Date[Date] = "15.10.21")))`
I used 15.10.21 as an example value to test my query. But It didn't work, the date isn't filtered.
So what I am doing wrong ? And how can I write my 3 parameters?
EDIT
How can I add the values that are not in the last 30 days ?
You haven't mentioned the measure/column name which you are applying the filter, so I'm assuming it as a Measure([Measure_Value]).
If your user is only selecting only single option at a time, you can use a switch case to filter the expression based on slicer value.
You can calculate the current date using TODAY() and on the basis of that you can calculate other time values like this:
var _month = MONTH(_today)
var _year = YEAR(_today)
var _last_30_days = _today - 30
On the basis of these values and switch case, you can create the measure:
Measure =
var _today = TODAY()
var _month = MONTH(_today)
var _year = YEAR(_today)
var _last_30_days = _today - 30
return SWITCH(SELECTEDVALUE(Parametres[Selection_date]),
"MonthToDate",CALCULATE([Measure_Value],FILTER(ALL(v_Date),MONTH('v_Date'[Date])=_month && YEAR('v_Date'[Date])=_year)),
"Last30Days",CALCULATE([Measure_Value],FILTER(ALL(v_Date),'v_Date'[Date]>_last_30_days)),
"YearToDate",CALCULATE([Measure_Value],FILTER(ALL(v_Date),YEAR('v_Date'[Date])=_year)),
BLANK())
In your measure formula you need to add the expression that you want to calculate, so if it's a sum or a count of records that's what you pick.
One way of doing it could be:
Measure = Count(Data[Records])
Measure with Param =
var selectedParam = SELECTEDVALUE(Parametres[Selection_date])
var dateFilter = FILTER(Dates,
(selectedParam = "Last30Days" && Dates[Date] = DATE(2021,01,19)) ||
(selectedParam = "MonthToDate" && Dates[Date] > DATE(2021,01,19)) ||
(selectedParam = "YearToDate" && Dates[Date] > DATE(2021,01,19)) ||
(ISBLANK(selectedParam)))
//note: the date filters are just an example, not how you would actually slice these.
return CALCULATE([Measure], dateFilter)
But you should look into Calculation Groups, as it is the nicest way to do what you're after. https://www.sqlbi.com/blog/marco/2020/07/15/creating-calculation-groups-in-power-bi-desktop/
I have a date table that is used to populate a date slicer. The date slicer filters all other filters on the page but one. The one it doesn't filter has a one-to-many relationship back to the date table.
However, when I use the data from table two as an axis (Date and Hour) it actually displays all date/hours from the entire table but doesn't restrict the date/hour range to that of the parent date table (table one). Thoughts on how I can achieve this without using merge tables (preferable in DAX)?
In SQL Server I would do the following to achieve this output:
select fc1.calendardatewithtime, totaltable.total
from FiscalCalendarWithTime fc1
cross apply (
select top(1) count(distinct id) total
from ActionDetail ad1
where ad1.upgraded_on=fc1.calendardatewithtime and ad1.status=3
)as totaltable
where exists ( select 1 from dbo.FiscalCalendarTable fc2 where fc2.calendardate=fc1.calendardate and fc2.fiscalweek=1 )
order by fc1.calendardatewithtime asc;
Where calendardatewithtime is the date with time field that I would use as the axis and totaltable.total is the value I would display as the graph total.
My Date Slicer code:
SpecialDateDropdown =
VAR _datetable = FiscalDGCalendar
VAR _today = TODAY()
VAR _yesterday = TODAY()-1
VAR CurrentFiscalWeek = calculate(min(FiscalCalendar[fiscal_week]),filter(FiscalCalendar,format(now(),"mm/dd/yyyy")=format(FiscalCalendar[fiscal_date],"mm/dd/yyyy")))
VAR CurrentFiscalPeriod = calculate(min(FiscalCalendar[fiscal_period]),filter(FiscalCalendar,format(now(),"mm/dd/yyyy")=format(FiscalCalendar[fiscal_date],"mm/dd/yyyy")))
VAR CurrentFiscalQuarter = calculate(min(FiscalCalendar[fiscal_quarter]),filter(FiscalCalendar,format(now(),"mm/dd/yyyy")=format(FiscalCalendar[fiscal_date],"mm/dd/yyyy")))
VAR CurrentFiscalYear = calculate(min(FiscalCalendar[fiscal_year]),filter(FiscalCalendar,format(now(),"mm/dd/yyyy")=format(FiscalCalendar[fiscal_date],"mm/dd/yyyy")))
RETURN UNION(
ADDCOLUMNS(FILTER(_datetable,[fiscal_date]=_today),"Period","Today","Order",1),
ADDCOLUMNS(FILTER(_datetable,[fiscal_date]=_yesterday),"Period","Yesterday","Order",2),
ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_week]=CurrentFiscalWeek),"Period","Current Fiscal Week","Order",3),
ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_week]=CurrentFiscalWeek-1),"Period","Prior Fiscal Week","Order",4),
ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_period]=CurrentFiscalPeriod),"Period","Current Fiscal Month","Order",5),
ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_period]=CurrentFiscalPeriod-1),"Period","Prior Fiscal Month","Order",6),
ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_quarter]=CurrentFiscalQuarter),"Period","Current Fiscal Quarter","Order",7),
ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear),"Period","Current Fiscal Year","Order",8),
ADDCOLUMNS(_datetable,"Period","Custom Date Range","Order",9)
)
And this is how I am gathering my totals so the only piece I am missing is how to visually display only a specific date range:
CALCULATE(
IF(
ISBLANK(DISTINCTCOUNT(ActionHistoryDetail[id])),0,DISTINCTCOUNT(ActionHistoryDetail[id])
),ActionHistoryDetail[status]=3,USERELATIONSHIP(FiscalCalendar[fiscal_date],fiscalcalendarwithtime[CalendarDate]),USERELATIONSHIP(fiscalcalendarwithtime[CalendarDateWithTime],ActionHistoryDetail[upgraded_on])
)
You can group the slicers in a single family, as all the slicers will have the same values(if values are the same). Then you can hide the second slicer behind the first slicer.
As you can see Date Table doesn't filter DATA TABLE as I haven't grouped them yet.
Now I got to View in the ribbon and select the sync slicers option and then go to Advanced Controls and group both of the slicers as A.
View >> Sync Slicers >> Advanced Options
Now as both of the slicers are grouped, when I sleect the Year from the Data Table slicer it filters the DATA TABLE table too.
Now just hide the other slicer.
If this answer helped you, then mark it as answer. Thanks.
You should check your relationships.
Make sure you have a date table mapping to your main table.
I have table Company. I need to display the TOP 6 recently created.
Exemple of data:
Expected results
What I tried :
Rank =
VAR d = Companies[CreatedDate].[Date]
RETURN
CALCULATE (
RANK.EQ ( d, Companies[CreatedDate], DESC)
)
the calculated column returned wrong values:
I need to order by creatd date, and when it's the same date, I need to order by Company Namr
How to correct it!,
For ranking based on created date and company name try the following steps, and if it helps accept it is as answer.
Create a calculated column for ranking the company name.
Company Sort = RANKX(ALL('Table'), 'Table'[Company Name], , ASC)
Create another calculated column for ranking using following DAX
Ranking on Date and Company Name =
VAR X = MAX('Table'[Company Sort])
var res =
RANKX(
ALL('Table),
'Table'[Created Date] * X + 'Table'[Company Sort]
)
RETURN res
Sort by using the column `Ranking on Date and Company Name'.
If you want to create a visual, then just add the column `Ranking on Date and Company Name' in the filter pane and select the Top N filter accordingly.
I have a date filter for my dashboard and depending on which end of month date the user selects the dashboard displays the appropriate values for the selected month and all of that works correctly. However I would like my date filter to be sorted in DESC order for the user so they do not have to scroll down to the bottom to get the most recent month. I have sorted the dataset in DESC order for the query tied to my dashboard, I have gone to the DATA tab within Power BI and sorted the dataset in DESC order but no matter what I try the filter will not sort in DESC order. Any help is much appreciated.
Unfortunately in page level filters there is no option to sort date to descending order.
One option is to use a Date slicer and sort it descending.
But if you cant have date slicer then a work around is there to implement this.
For this you need to create two calculated columns. One a duplicate column of your date field and another to sort this field.
SortCol = Table[EOM Date]*-1
EOMDateCopy=LEFT([EOM Date],LEN([EOM Date]))
Sort the EOMDateCopy column with SortCol and drag EOMDateCopy in your page level filter.
Best Regards,
Shani
My suggestion is to build your own Calendar table. In "Data" View, create a new Table by writing DAX similar like this:
Calendar =
VAR _MinDate = MIN('YourFactTable'[Date])
VAR _MaxDate = MAX('YourFactTable'[Date])
VAR _BaseCalendar = CALENDAR(_MinDate,_MaxDate)
RETURN
GENERATE(
_BaseCalendar,
VAR _BaseDate = [Date]
VAR _Year = YEAR(_BaseDate)
VAR _Month = MONTH(_BaseDate)
VAR _Quarter = QUARTER(_BaseDate)
VAR _Day = DAY(_BaseDate)
RETURN
ROW (
"Calendar Year", _Year,
"Calendar Month", _Month,
"Calendar Year-Month", _Year&"-"&IF(LEN(_Month)=1,"0"&_Month,_Month),
"Calendar Quarter", FORMAT(_Quarter,"\Q0"),
"Date Order", 9999 - (_Year+_Month+_Day)
)
)
"Date Order", 9999 - (_Year+_Month+_Day) create a descending order for your date.
Next, build a relationship between your Calendar table and your Fact table by relating the "Date" column of your Calendar table and your date column (version_no in my case) of your Fact table. Make sure these two columns have exactly the same date format.
Finally, click on the column and set "Sort by column" as Date Order
You will see your date filter is sorted in desc.
Please make sure your date field is in proper format and then try to sort.
If it is already in date format, please give a bit more details so that we can check.
Best Regards,
Shani