Order date in a table - powerbi

Hi I'm trying to order a table in BI by monthNumber, but now I have same months in differents year, and PowerBI doesn't care about that. I have:
Jan-20
Feb-19
Feb-20
Mar-19
Mar-20
Apr-19
May-19
Jun-19
Jul-19
Aug-19
Sep-19
Oct-19
Nov-19
Dec-19
And I want:
Feb-19
Mar-19
Apr-19
May-19
Jun-19
Jul-19
Aug-19
Sep-19
Oct-19
Nov-19
Dec-19
Jan-20
Feb-20
Mar-20
NOTE: Each month I will add a new month (The actual current month e.g. Now Aug-20) and this should still work properly

Let your table name is "order_by_month" and the column name is "month_year". Now just follow this following steps to order data as per your requirement.
Step-1: In Power Query, create a custom column as below image-
We are generating this column with the First date of each month so that we can order our original data later based on the Date value. The generated value in the new column will look like below-
Step-2: Change the above red marked column's data type as Date.
Step-3: Get back to report by clicking the "Close & Apply" Button.
Step-4: In the report, go to Table view and select your original column "month_year" and order this column by newly created column "date_formatted_value" as shown in the beloe image.
Now the final output will be sorted as below as you wants-

Related

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).

how to show data based on date slicer but from 2 dates columns

Currently, I have a report that displays a series of data that I can filter on the basis of a "date slicer (type 'between')". This slicer works with as specifi column "i_date" because a date table (m_date[date]) is used for the slicer and the "i_date" (from another table "interv") is linked together (1:n relathions).
In this other table there is another date type column with the last modification date of the row (interv[modified]).
Now, when a period is selected with the date slicer, I'd like to show the data where interv[i_date] OR interv[modified] are inside the selected period.
How can I do that ?
Using a new column with the newest date between interv[i_date] OR interv[modified] is not a solution, because in this case if a row is modified after the period, it will not be shown. (because interv[i_date] < interv[modified])
solved with a second slicer simply

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-

PowerBI - conditional formatting for highlighting weekends

I have a data table matrix in power bi showing Dates in Rows and hours in columns and count of customers against them as values. i wanted to highlight all rows of thursday, friday and saturday, so that weekend figures can be compared.
Need help in this pls...
the table is in the below format
enter image description here
First you want to create a duplicate (in my case monday - friday (2) that does NOT have a relation to you source table. You want this duplicate table to only show days. This duplicate table needs a relationship with the slicer you are going to use to filter for days
In your source table (monday - friday) you want to create the following measure:
Measure = IF(HASONEVALUE('monday -friday (2)'[Day]);
IF(SELECTEDVALUE('monday -friday (2)'[Day]) = MAX('monday -friday'[Day]); 1; 0);
IF(ISFILTERED('monday -friday (2)'[Day]) && COUNTROWS(FILTER('monday -friday (2)'; 'monday -friday (2)'[Day] = MAX('monday -friday'[Day]))); 1; 0))
Now you want to create conditional formatting. First create your table with days and values (for the example i did not sort the table. You want to sort your table so it looks better):
Then right click on values and select conditional formatting. Select based on rules.
and the measure you just created in your source table.
for the first option you select "is bigger than or equal to" and give it a value 1.
for the second option you select "is smaller than"and give it a value 1000.
Choose the color you want your highlights to be.
If you now select a day in your filter the value for that day will show the background color you selected! In your case you want to select all days you want to have highlighted.
Hope this helps!

Create table comparing Two Queries with identical fields/field names

I would like to create a table to compare Month To Date (MTD) Vs YTD Sales data metrics
I am using two queries:
1st query = YTD Sales data (Two fields: Sales and Quotes)
2nd query = MTD Sales Data (Two Fields: Sales and Quotes).
Each query has the same field names, just different data
I would like to output a table like the following
How to I create the above table? At the moment I can only create a table like the following:
The latter 1x4 table only works if I appropriately name the fields. But definitely isn’t what I want, because with enough fields, the table could go on forever.
Any help would be appreciated
In the query editor, create a label column for each table that labels what they are and then append the two tables together so you get something like this:
Then you can create a matrix visual with the Label column in the Columns field and the Sales and Quantity columns in the Values area.
Make sure you've switched "Show on Rows" to "On" under the Format > Values section of the Visualizations pane.