How to dynamically filter to only dates in 2 months time using Excel PowerQuery - excel

I'm using Excel and PowerQuery to show different tables of data, each table showing the data for that month. I'm using the built-in date operators 'This Month' and 'Next Month' but there's not one for 2 months time.
I can select an arbitrary month, but that doesn't work because I need the data in the tables to automatically refresh when we move to the next month.
I can see in the advanced editor that the formula for next month is = Table.SelectRows(#"Removed Columns", each Date.IsInNextMonth([#"Forecast Date (DD/MM/YYYY)"])) but I can't work out how to adapt this to show 2 months time...
Any help/guidance much appreciated!

You could use the greater than...less than method and construct your dates based on Today's date:
#"Filtered Rows" = Table.SelectRows(#"Changed Type",
each [dates] >= #date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow())+1,1)
and [dates] < #date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow())+2,1))
where [dates] is your column containing the dates you want to filter, and Changed Type is the previous line in your code.

Related

Format text column as a date unless there is specific text

I am new to Power Query.
I have a database, containing all text fields, to populate onto an excel spreadsheet as a requirement for business purposes. I am not allowed to add or delete tables in the spreadsheet. The problem I'm having is with the End Date column.
The End Date column can either have a date format or "TBD" as text if there is a start date but no end date.
Essentially I need power query to format the incoming in the End Date column as a date, unless the row contains "TBD". In that case I need the row to remain as "TBD". However as you can see from the picture above, it fails to populate correctly.
This is the formula I've been trying to get working but I haven't had any luck. Is there a way to accomplish this task?
= Table.TransformColumns(
_qryPerstat,{{"END DT",
each if qryPerstat[END DT] = "TBD" then "TBD" else Date.From(DateTimeZone.From()), type date}})

Use a report filter directly in power-query-result-table

Power-Query-Result-Table
Pivot-Table on Power-Query-Result-Table
I am getting the list in the first screenshot as a result from the Power-Query-Editor.
Now I want to apply a Report Filter to it. Therfore, I put the data into a Pivot-Table.
In general this solution is working but I am wondering if it is possible to have the Report Fitler directly in the Power-Query-Result-Table to avoid an additional Pivot-Table?
You can filter for crew directly in the PowerQuery using the drop down atop the crew column like below image. In this image I filter for Crew=J
That generates code as follows:
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Crew] = "J")
If you put J into a a cell on the excel sheet and gave that cell a range name like CrewName, you could reference that range name in the powerquery and filter dynamically
#"Filtered Rows"= Table.SelectRows(#"Changed Type", each [Crew] = Excel.CurrentWorkbook(){[Name="CrewName"]}[Content]{0}[Column1])

create calculated last year date on selected month only in powerbi

I have data column name "Loss Date" I want to create new column "Policy Date" based on this column and the condition is if Month<4 then display last year date otherwise not. actually, I want to create Policy Date column and I want to display in this bar chart which is given below,
can anybody helps me regarding this in PowerBI?
In Power Query Editor, add a custom column with this below code-
=if Date.Month([loss date]) < 5 then "Apr-"& Text.From(Date.Year([loss date]) - 1) &" to Mar-"& Text.From(Date.Year([loss date])) else "Apr-"& Text.From(Date.Year([loss date])) &" to Mar-"& Text.From(Date.Year([loss date]) +1)
Here is the output-
Now you can use that new column to your chart for generating Bars.

How can I find/highlight recurring values in multiple columns on Excel

I need to find/highlight duplicate values which occur in each of the 8 columns within my worksheet (found here). The columns are from D0 to D8 and have varrying rows in them. I have tried solutions provided here. The solutions I used are;
(1)
=LOOKUP("zzz",CHOOSE({1,2},"",INDEX(A$2:A$10,MATCH(0,COUNTIF(E$1:E1,A$2:A$10)+IF(IF(COUNTIF(B$2:B$8,A$2:A$10)>0,1,0)+IF(COUNTIF(C$2:C$9,A$2:A$10)>0,1,0)=2,0,1),0))))
and
(2)
=INDEX($A$2:$A$10, MATCH(0, COUNTIF($E$1:E1, $A$2:$A$10)+IF(IF(COUNTIF($B$2:$B$8, $A$2:$A$10)>0, 1,
0)+IF(COUNTIF($C$2:$C$9, $A$2:$A$10)>0, 1, 0)=2, 0, 1), 0))
I substituted the values as per my own worksheet but each time I just got "0" as an answer even though that is not possible. Just by looking at the first 2 rows one can easily tell that there are values which occured in all 8 columns.
I am a beginner in Excel and currently using Microsoft Excel 2016 for Mac (Ver 16.16.14).
EDIT #2
Found an error within the nested IF functions from the second formula you provided.
In the formula you tried to do IF(IF(A)+IF(B)=2,0,1) but the correct way should be IF((IF(A)+IF(B))=2,0,1) in my opinion.
Based on the sample worksheet you provided, enter the following formula in Cell J2:
=INDEX(A$2:A$861,MATCH(0,COUNTIF(J$1:J1,A$2:A$861)+IF((IF(COUNTIF(B$2:B$243,A$2:A$861)>0,1,0)+IF(COUNTIF(C$2:C$162,A$2:A$861)>0,1,0)+IF(COUNTIF(D$2:D$132,A$2:A$861)>0,1,0)+IF(COUNTIF(E$2:E$118,A$2:A$861)>0,1,0)+IF(COUNTIF(F$2:F$112,A$2:A$861)>0,1,0)+IF(COUNTIF(G$2:G$94,A$2:A$861)>0,1,0)+IF(COUNTIF(H$2:H$81,A$2:A$861)>0,1,0))=7,0,1),0))
Please note it is an array formula so you need to do the following after entered the above formula:
Select the range, press CONTROL + U and then press COMMAND + RETURN
In case the above does not work for you:
Select the range, press CONTROL + U and then press COMMAND + SHIFT + RETURN
Please read this if you are still unclear: How to Use Array Formula in Excel Mac (Who'd knew using array formula in Excel for Mac is such a pain...)
Drag the formula down until the list is returning #N/A error which means you have found all common values.
Suppose you have named this list of common values as List, my experience in Excel 2016 for Windows is that you go back to your source table, highlight the whole table, go to Conditional Formatting under Home Tab, go to New Rule..., go to the last option, and enter the following formula as the formatting rule:
=MATCH(A2,List,0)>0
Given that Power Query is not supported in Excel 2011 and Excel 2016 for Mac, please disregard the following approach using Power Query. FYI power query approach is way faster than the above array formula approach in this case...
Judging from your post and the example you provided, I think you want to find common values that have presented in all 8 Columns, which means you will ignore values that appeared in 7, 6, 5 or lesser columns.
Given that you are dealing with a large data set (860 x 8), I suggest to use Power Query to tackle the problem. Power Query is a built-in function in Excel 2010 Professional Plus and all later versions of Excel.
Steps are:
Use From Table function under Data tab to load your data to the Power Query Editor;
Highlight all columns, then use Unpivot Columns function under Transform tab to transform the table into a 2-Column table;
Use Group By function under Transform tab group Value column by counting distinct rows as set out below;
Right click the filer box on the right of the column header to filer the list by 8 which will return values that appeared in all 8 columns;
Close & Load the column (which is actually a one-column table) to a new worksheet (by default).
Here are the power query M codes behind the scene for reference only. All steps are using built-in functions of the editor which is quite straight forward.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"d0", Int64.Type}, {"d1", Int64.Type}, {"d2", Int64.Type}, {"d3", Int64.Type}, {"d4", Int64.Type}, {"d5", Int64.Type}, {"d6", Int64.Type}, {"d7", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Value"}, {{"Count", each Table.RowCount(Table.Distinct(_)), type number}}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Count] = 8)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Count"})
in
#"Removed Columns"

"Year" and "Weeknum" Function in excel 2013

I have a problem with the "Year" and "Weeknum" functions in excel 2013.
I tried the formula below using the functions:
=YEAR(RC[1])&"_WW_"&IF(Weeknum(RC[1])<10,"0"&Weeknum(RC[1]),WeekNum(RC[1]))
On some dates, I get back "#VALUE!" and
And the correct field for other dates...
for example:
for the date "11/30/2013 20:15:00", I'm getting "#VALUE"
for the date "12/07/2013 20:15:00", I'm getting "2013_WW_28"
when evaluating formula, both "Year" and "weeknum" return "#VALUE!".
and On both of the examples, the date field is set as "General" (trying playing with it and change it to "long date" or "short date"' and it didn't work...)
If the format is general in this context that means your "dates" are text values
The only dates that are deemed valid are those where day <= 12......and those are being interpreted the wrong way round hence wrong WEEKNUM.
You can try changing to valid dates with "text to columns" but you may lose the times, is that a problem?
Select date column then.....
Use Data > Text to Columns > "Fixed width" > Next > at step 2 insert a line between times and dates > Next > at step 3, with date column selected, under "column data format" choose "date" and the source format (MDY) > OK
This should convert to valid date format for your region and formula should work as expected

Resources