Power BI - Get the Days of current Month - powerbi

I have a column "Days of Month" which is just rows from 1 to 31 and a filter above with the date as you can see in the screenshot below. I want to filter this column to show me the days of each month based on the filter above.
For example if the date above is 2/2/2020 i would like to see 28 rows on my column.
I tried several solutions but i couldn't achieve this.
Can anyone help me ?

I was able to get this working by duplicating the date table and creating a relationship to its duplicate on year and month.
Add a [YearMonth] column to your date table
Duplicate the Dates table as Dates2
Create a many-to-many data relationship between Dates and Dates2 on the [YearMonth] column. Set the cross filter direction to Single (Dates filters Dates2)
Set up your report to use a slicer or filter on Dates[Date] and display Date2[Day] in a table visual. Here is the result:

Related

Create Rows to the table where the data is missing for specific dates in power BI

I have a table with below columns in my dataset. We have monthly revenue for each resellers in this table.
For few resellers, there will be no data for some particular months, as they didn’t generate revenue on those months. I want to create rows for those resellers with the missing date and the revenue for those missing dates to be updated as blank.
Please advise how we can achieve this.
Current data:
Expected result:
For the missing dates you need to create a date table using the CALENDAR function like this:
Date table = CALENDAR(MIN(Date), MAX(Date))
This will create a table with a single colmn containing all the dates in your table with filled gaps (even if you don't have certain dates in your table). Then you need to create a relationship between your table and the date table.
When you use the date and the revenue in a visual lets say table or matrix all dates will be visible but the revenues will be blank (except for those that actually had a value in revenue).

Finding Previous year Sales in Power BI with week number

I am trying to find the Previous year sales for the same week in Power BI.I dont have any date column.
I have two table one is FACT Indicators table as shown below:
and one sales table( Fact Sales table):
I want to create one calculated field namely(Sales Previous Year) to show the previous year sales for the same week .
In 'Fact Indicators' table 'PY 52 week flag' filed shows if this week id is Previous year or not.
Week column shows the week number from 1 to 52 weeks .
Week Id shows the unique number per Market key.
'Market_Week Id Key' is the common joining key between FACT Indicators table and Fact Sales table
Please help me to find the formula for calculated field.I dont have the date field in my raw data
Every time you deal with anything related to dates, you will need to add what we call a date dimension. It will save you tons of headaches. Once you have it in you will be able to hook it into the creation of the calculated filed.
you can google power bi or ssas date dimension and find tons of information on it.
Yeah! I guess SQL Technical team can be a tough crowd.... Well! In this case, I would recommend bringing the Year into FactSales Table from Fact Indicator . You have two options here with physical relationship set up between Market Week Id Key in both tables you can build a calc column with
Year = CALCULATE(VALUES(FactIndicators[Year]))
or without relationship use LOOKUPVALUE on WeekId
Year = LOOKUPVALUE(FactIndicators[Year], FactIndicators[WeekId], FactSales[WeekId])
Sales Last Year calc colum :
SalesLastYear =
CALCULATE (
SUM(FactSales[SalesThisYear] ),
TOPN(1,
FILTER(
FactSales,
FactSales[Year] < EARLIER(FactSales[Year])
&& FactSales[Key] < EARLIER(FactSales[Key])
)
)
)

Calculate Works until i add FILTER

I'm learning DAX and I'm trying to make a measure for Sales Last year.
this formula works :
Sales LY = CALCULATE([Sales CY],SAMEPERIODLASTYEAR(Date[Date]))
But when I add FILTER to the measure, it gives me the values from the current year like "Sales CY"
Sales LY = `CALCULATE([Sales CY], Filter (dim_date, SAMEPERIODLASTYEAR (Date[Date]) ))`
I already have a date filter on the page relative date in this year
the invoices Table and Date table are joined on the date of the creation of the invoice (createdat)
Any ideas what's the meaning behind the things in blue circles?
The FILTER function expects a condition that can be checked for each row of the table instead of a column of dates returned by SAMEPERIODLASTYEAR, so I wouldn't expect the second version to work.
I think the bits circled in blue are emphasizing that you are connected an imported data table to a DirectQuery table (different storage modes).

Power BI - Select Slicer Date Between 2 Columns

Hopefully a quick explanation of what I am hoping to accomplish followed by the approach we've been working on for over a year.
Desired Result
I have a table of SCD values with two columns, SCD_Valid_From and SCD_Valid_To. Is there a way to join a date table in my model (or simply use a slicer without a join) in order to be able to choose a specific date that is in between the two SCD columns and have that row of data returned?
Original Table
ID | SCD_Valid_From | SCR_Valid_To | Cost
1 2020-08-01 2020-08-03 5.00
Slicer date chosen is 2020-08-02. I would like this ID=1 record to be returned.
What We've Attempted So Far
We had a consultant come in and help us get Power BI launched last year. His solution was to create an expansion table that would contain a row for every ID/Date combination.
Expanded Original Table
ID | SCD_Valid_Date | Cost
1 2020-08-01 5.00
1 2020-08-02 5.00
1 2020-08-03 5.00
This was happening originally on the Power BI side, and we would use incremental refresh to control how much of this table was getting pushed each day. Long story short, this was extremely inefficient and made the refresh too slow to be effective - for 5 years' worth of data, we would need over 2000 rows per ID just to be able to select a dimensional record.
Is there a way to use a slicer where Power BI can select the records where that selected date falls between dates in two columns of a table?
Let me explain a workaround and I hope this will help you to solve your issue. Let me guess you have below 2 tables-
"Dates" table with column "Date" from where you are generating the date slicer.
"your_main_table" with with column "scd_valid_from" and "scd_valid_to".
Step-1: If you do not have relation between table "Dates" and "your_main_table", this is fine as other wise you have to create a new table like "Dates2". For this work around, you can not have relation between those tables.
In case you have already relation established between those tables, create a new custom table with this below code-
Dates2 =
SELECTCOLUMNS(
Dates,
"Date", Dates[Date]
)
From here, I will consider "Dates2" as source of your Date slicer. But if you have "Date" table with no relation with table "your_main_table", just consider "Dates" in place of "Dates2" in below measures creation. Now, Create these following 4 measures in your table "your_main_table"
1.
date_from_current_row = max(join_using_date_range[SCD_Valid_From])
2.
date_to_current_row = max(join_using_date_range[SCD_Valid_to])
3.
date_selected_in_slicer = SELECTEDVALUE(Dates2[Date])
4.
show_hide_row =
if(
[date_selected_in_slicer] >= [date_from_current_row]
&& [date_selected_in_slicer] <= [date_to_current_row]
,
1,
0
)
Now you have all instruments ready for play. Create your visual using columns from the table "your_main_table"
Final Step: Now just add a visual level filter with the measure "show_hide_row" and set value will show only when "show_hide_row = 1".
The final output will be something like below image-

Date range filter in clustered column chart

In my Power BI report I have a date slicer and a clustered column chart. In the chart I want to display how much events occurred per hour. For that I have a data table like this:
Date Hour Count
01.01.2019 07:00:00 4
01.01.2019 09:00:00 9
03.01.2019 07:00:00 1
07.01.2019 10:00:00 14
and so on ...
The charts x-axis displays the hour, y-axis the count.
Now I want to be able to filter the chart by date when I change the date range in the slicer. For example when I set the slicer to the range from 04.01.2019 to 10.01.2019, the chart should display the hour histogram only of these 7 days.
Hope you have an idea what I want to do.
Thanks in advance!
EDIT
I've found out why it is not working. The report contains multiple charts, each bound to an own data table. Each table has a date column. The slicer uses one of these date columns, but not the one of the data used by the clustered column chart. Now the date column of the clustered column chart can contain one date multiple times. But the date column which is used by the slicer contains each date only once.
The data table used by the slicer looks like this:
Date some other columns
01.01.2019 ...
02.01.2019 ...
04.01.2019 ...
...
Each date is contained once at the most in contrast to the date column of the first table, where each date can appear more than once. Because of this the slicer works for the one chart but not for the other.
Ok, found the solution and it is very easy. All you have to do is to create a relationship between the date column of table two and the date colum of table one. The slicer uses the date column of table two. If you change the date range now this affects the clustered column chart too.