Slicer managing multiple columns across tables simultaneously - powerbi

I have a report page which contains tables about cars and bikes. Each of them is a separate table like:
Cars
Id | CarName | Time1
Bikes
Id | BikeName | Time2
There are no relationships between these tables however they must be displayed in same page. How can i use a Slicer or a Timeline 2.0.1 to manipulate all dashboards simultaneously by just filtering once the date?
I.e. If i select interval between 01/01/19-02/02/19 it will filter the Cars by field Time1 and the Bikes by Time2 and display the dashboards accordingly?
Thanks so much!

Build a CalendarTable and link both tables bikes and cars to it. You may find lots of propositions of CalendarTables. Then make slicer on CalendarTable. Beware not to make slicer on your fact tables bikes or cars.
There are more advantages to using CalendarTable then just the possibility of filtering multiple tables. I would use CalendarTable even with a single table because it contains complete list of days - your bike table may not - and that is why time intelligence functions work properly. And mind the performance - slicing small and unique CalendarTable is faster then big fact tables.
Here is an example of simple CalendarTable. Choose in menu Modeling / New Table:
Calendar =
GENERATE (
CALENDAR (
DATE ( 2016, 1, 1 ),
DATE ( 2020, 12, 31 )
),
VAR CurrentDay = [Date]
VAR day = DAY ( CurrentDay )
VAR month = MONTH ( CurrentDay )
VAR year = YEAR ( CurrentDay )
VAR YM_text = FORMAT ( [Date], "yyyy-MM" )
RETURN
ROW (
"day" , day,
"month" , month,
"year" , year,
"YM_text" , YM_text
)
)
Set up min and max date. Here from 2016-01-01 to 2020-12-31.

Related

Find number of orders for customer first month

I am new to Power BI and learning how to perform cohort analysis with DAX in Power BI. Is there any way to find out how many times (or if easier if a customer buys more than a certain threshold) their first month?
If I have the table Customers:
ID | DateOfFirstRegistration
And the table of orders:
ID | customerId | orderDate
Let me know if any more information is helpful!
EDIT: If possible, is it also possible to plot it in a matrix with customers in each row and month 1 through 3 in the columns?
Thank you
You can do something like this measure in a table visualization together with customer ID:
First Month Purchases =
VAR _registration =
SELECTEDVALUE ( 'customers'[DateOfFirstRegistration] )
RETURN
CALCULATE (
COUNTROWS ( 'orders' ) ,
DATESINPERIOD (
'orders'[orderDate] ,
_registration ,
1 ,
MONTH
)
)

Set First day of the range as Initial Inventory + Production - Sales = Inventory (DAX)

My challenge has been how to
01 - set Initial Inventory (considering the first day of the column);
02 - From the second day on, have Forecast (Previsão) - Sales (Vendas) = Balance. So 3 columns for each day
The way it is now, it repeats Initial Inventory throughout the days.
Here's the goal I'm trying to achieve:
Here's how the tables are related:
I would try to approach it with an unrelated helper table, that would contain 2 columns and 4 rows. Here's an example based on Contoso data.
Here's the helper table. Column Item ID is used for sorting result columns as well:
And now comes the magic:
Helper measure =
VAR minDate =
CALCULATE ( MIN ( DimDate[Datekey] ), ALLSELECTED ( DimDate ) )
VAR curDate =
SELECTEDVALUE ( DimDate[Datekey] )
RETURN
SWITCH (
SELECTEDVALUE ( Helper[Item ID] ),
1, IF ( curDate = minDate, [Opening Inventory Qty], BLANK () ),
2, [Production Qty],
3, - [Sales Qty],
4, [Closing Inventory Qty]
)
Here's an explanation:
minDate is used to get initial date on the visual
curDate is used to get current date
Next I check, which column from the helper table the measure is calculated for using SWITCH function
using SWITCH, I return different formula, based on helper column type
for Opening inventory, I only return a value when current date is equal to initial date. Otherwise, I return BLANK() - that's why Opening inventory only appears on the first date
The matrix visual is built using Product name in rows; Year, month, day and Item (from the helper table) in columns, and the Helper measure from above.
Here's a the result (don't mind quantities, it's a sample data):
EDIT:
For completeness' sake, here's how the model looks. Notice that the Helper table is not related to any other table:

DAX PowerBI SUM from the beginning up to current date (input by user)

I have 4 tables Calendar, Products, Region, and Sales. Then I create the relationship between 4 tables through
Region.Region_code -> Sales.Region_Code
Product.Product_wid -> Sales.Product_wid
Calendar.Cal_Row_wid -> Sales.Date_wid
Then I create 2 slicers Date and Month:
I would like to write a measure to calculate the Total quantity_rcs (which belongs to table Sales) for all order from the beginning up to current date (which characterized by Date and Month; both of them belong to Calendars).
How this should work if you have multivalue slicer?
belove example for onevalue slicer where we are pointing to specific date (consider that you have a unique date column In calendar maybe "issue_date"):
Measure =
var __date = calculate(max(Calendar[issue_date]), FILTER(ALL(Calendar[Date]
,Calendar[Month],Calendar[Year]),
Calendar[Date] = SELECTEDVALUE(Calendar[Date]) &&
Calendar[Month] = SELECTEDVALUE(Calendar[Month]) &&
Calendar[Year] = YEAR(TODAY())
)
)
return
calculate( sum(Sales[quantity_rcs]),
FILTER(ALL(Calendar[issue_date]),
Calendar[issue_date] <= __date )
)

Custom Calendar for sales data aggregated by weeks and months

I am struggling with creating Custom Calendar that would allow me to use time intelligence function on data that is already aggregated by weeks and months. The original table with transactions contains over 20M rows, so for performance and space saving reasons the grouping is necessary and I perform it while querying the database in SQL Server. I want to create:
Month vs Same Month Last Year
Week vs Same Week Last Year
Year-To-Date vs Last Year Year-To-Date (by Months)
Year-To-Date vs Last Year Year-To-Date (by Weeks)
My idea was to assign some dummy dates to each row of data, and then create custom calendar that would have each of these dummy dates along with other details. I just cannot figure out the key (how to create dummy date having Year number Month number and Week number - please keep in mind that for example Week 5 of 2020 is partially in January and partially in February)
Is it possible? Maybe I have to create 2 separate Calendars, one for Weeks and one for Months?
Add calculated table:
Calendar =
GENERATE (
CALENDAR (
DATE ( 2016, 1, 1 ),
DATE ( 2020, 12, 31 )
),
VAR VarDates = [Date]
VAR VarDay = DAY ( VarDates )
VAR VarMonth = MONTH ( VarDates )
VAR VarYear = YEAR ( VarDates )
VAR YM_text = FORMAT ( [Date], "yyyy-MM" )
VAR Y_week = YEAR ( VarDates ) & "." & WEEKNUM(VarDates)
RETURN
ROW (
"day" , VarDay,
"month" , VarMonth,
"year" , VarYear,
"YM_text" , YM_text,
"Y_week" , Y_week
)
)
You can customize it. In relation pane connect your Date field of FactTable (which is by week, as you say. This table can have missing dates and duplicate dates, to be precise) to the field Date of the Calendar table (which has unique Date, by day). Then, in all your visuals or measures always use the the Date field of the Calendar table. It is a good practice to hide the field Date in your FactTable.
More explanations here https://stackoverflow.com/a/54980662/1903793

Custom Date Table Drill-down Issue Power BI

Using the built-in Power BI date table, you are able to drill down from year -> Qtr -> month effortlessly, as shown below:
The date table used to generate the drill-down figure above:
DAX Formula: Cal = CALENDAR(MIN(Data[Date]),MAX(Data[Date]))
I would like to maintain this drill-down capability for the following custom date table:
Dates =
GENERATE (
CALENDAR ( DATE ( 2016, 10, 1 ), DATE ( 2025, 10, 1 ) ),
VAR currentDay = [Date]
VAR year =
IF ( MONTH ( currentDay ) >= 10, YEAR ( currentDay ) + 1, YEAR ( currentDay ) )
VAR quarter =
IF (
MONTH ( currentDay ) >= 10,
1,
IF ( MONTH ( currentDay ) <= 3, 2, IF ( MONTH ( currentDay ) <= 6, 3, 4 ) )
)
VAR month =
IF (
MONTH ( currentDay ) >= 10,
MONTH ( currentDay ) - 9,
MONTH ( currentDay ) + 3
)
RETURN
ROW ( "year", year, "quarter", quarter, "month", month )
)
It seems that the moment I mark "Dates" as the date table, I am unable to implement the built-in drill-down capability. I tried adding a date hierarchy, but cannot seem to control the order of the drill-down. For example, the visuals display month initially, and then "drill-down" to year, and finally to quarter. (this order doesn't make sense to me and I can't seem to change it). I need to be able to go from year -> quarter -> month, as before. I cannot use the default date table because I am using fiscal dates.
This is the result I am getting:
Please let me know if anything needs clarification, thank you!
I am able to sort in custom date table(with different fiscal year), Please find the snapshot attached for your reference.
I have used the power query to create a custom date table ( you can find the code here https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-2-fiscal-columns)
we just need to change the startdate, enddate and StartOfFiscalYear(custom fiscal month).
Try and let me know
You have defined your date hierarchy as Date > year > month > quarter, per your screenshot. The order of the fields in the hierarchy defines your drill order. You do not need to define a hierarchy, you can simply drop fields ad-hoc into the field well for any visual. But if you're using a hierarchy, you must define it in the correct order:
year > quarter > month > Date
You can see the order in your hierarchy:
You can reorder these fields by clicking and dragging them within the hierarchy, or by right clicking and selecting "Move up" or "Move down":