Quantcast
Channel: Power Query topics
Viewing all 31433 articles
Browse latest View live

Dynamic filter based on condition

$
0
0

Hi everyone,

 

I have a filter that shows only rows older than 60 days compared to the last day of the current month. The code looks like this:

 

#"Filtered Rows" = Table.SelectRows(Source, each [Rec Date] < Date.AddDays(DateTime.Date(Date.EndOfMonth(DateTime.LocalNow())), -60)),

However, I would like to use a different comparison date depending on the current day of the month. On day 1-5 every month, I would like the last day of the previous month to be used as a comparison date, and for all other days, the last day of the current month.

 

How can I do this? Can it be done using the if function somehow?

 

Thank you


PowerBi Gauge Visualization

$
0
0

Hii, all. I want to design a report like below screenshot. So I have stored the data in SharePoint list and connected the data to PowerBI desktop. I am a beginner to PowerBI. I have created below report using the radial gauge but the thing is I don't know how to add pointer in PowerBI radial gauge. And in the second screenshot how to add two items in the PowerBI radial gauge. In the PowerBI radial gauge value field, only one value can be added. How I can do Please help me?

 

PowerBIEx.png

Data wrangling a data set structured with information header and two column data below

$
0
0

So I have this report data generated from a system that I would like to wrangle to a good tidy format with power query. 

 

The data set has an information about the export in cell A1.

 

Then row 2-6 contains some informationd data for the series that in column. The timeseries data below is then divided with the first column beeing the actual timestamp following with the value and the status of that value (e.g. "Corrected" or "Calculated"). 

I would like to transform this in to a tidy dataset that has each variable as columns and every observation in the rows.

 

I've attached a spreadsheet with some sample data. In the tab "Base data" the data is the original format. I've added a tab "Wanted output" to show how I would like the data to look. 

 

Since I have multiple reports in this format I would ultimately make this in to a function to import and clean data from a folder structure.

 

Can't seem to attach a file so here is the original data:

 

Hourlist 2019-05-14 00:00 - 2019-05-22 23:00    
NameFacility 1 Facility 2 Facility 3 
Facility number      
Alternative Fac. Nr      
Serie-IDABC1 ABC2 ABC3 
Time formatNormal timeNormal timeNormal time
HourValueStatusValueStatusValueStatus
2019-05-14 00:000,00 0,00 0,00 
2019-05-14 01:000,00 0,00 0,00 
2019-05-14 02:000,00 0,00 0,00 
2019-05-14 03:000,00 0,04 0,04 
2019-05-14 04:000,33 0,49Corrected0,49 
2019-05-14 05:001,89 2,07 2,16 
2019-05-14 06:007,71 7,94 7,98 
2019-05-14 07:0015,35 15,67 14,82 
2019-05-14 08:0021,67 23,27 19,98 
2019-05-14 09:0025,66Calculated27,51 23,51 
2019-05-14 10:0027,32Calculated29,11 13,49Corrected
2019-05-14 11:0027,07 28,59 0,00Corrected
2019-05-14 12:0025,42 26,88 0,00Corrected
2019-05-14 13:0021,42 22,73 0,00Corrected
2019-05-14 14:0016,47 17,44 0,00Corrected
2019-05-14 15:009,30 10,12 0,00Corrected
2019-05-14 16:002,24 2,75 0,00Corrected
2019-05-14 17:000,80 1,13 0,00Corrected
2019-05-14 18:000,52 0,72 0,00Corrected
2019-05-14 19:000,07 0,14 0,00Corrected
2019-05-14 20:000,00 0,00 0,00Corrected

 

Optimal output:

HourValueStatusNameFacility numberAlternative Fac. NrSerie-IDTime formatSource
2019-05-14 00:000,00 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:00
2019-05-14 01:000,00 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:01
2019-05-14 02:000,00 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:02
2019-05-14 03:000,00 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:03
2019-05-14 04:000,33 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:04
2019-05-14 05:001,89 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:05
2019-05-14 06:007,71 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:06
2019-05-14 07:0015,35 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:07
2019-05-14 08:0021,67 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:08
2019-05-14 09:0025,66CalculatedFacility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:09
2019-05-14 10:0027,32CalculatedFacility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:10
2019-05-14 11:0027,07 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:11
2019-05-14 12:0025,42 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:12
2019-05-14 13:0021,42 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:13
2019-05-14 14:0016,47 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:14
2019-05-14 15:009,30 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:15
2019-05-14 16:002,24 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:16
2019-05-14 17:000,80 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:17
2019-05-14 18:000,52 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:18
2019-05-14 19:000,07 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:19
2019-05-14 20:000,00 Facility 1  ABC1Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:20
2019-05-14 00:000,00 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:21
2019-05-14 01:000,00 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:22
2019-05-14 02:000,00 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:23
2019-05-14 03:000,04 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:24
2019-05-14 04:000,49CorrectedFacility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:25
2019-05-14 05:002,07 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:26
2019-05-14 06:007,94 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:27
2019-05-14 07:0015,67 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:28
2019-05-14 08:0023,27 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:29
2019-05-14 09:0027,51 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:30
2019-05-14 10:0029,11 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:31
2019-05-14 11:0028,59 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:32
2019-05-14 12:0026,88 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:33
2019-05-14 13:0022,73 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:34
2019-05-14 14:0017,44 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:35
2019-05-14 15:0010,12 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:36
2019-05-14 16:002,75 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:37
2019-05-14 17:001,13 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:38
2019-05-14 18:000,72 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:39
2019-05-14 19:000,14 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:40
2019-05-14 20:000,00 Facility 2  ABC2Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:41
2019-05-14 00:000,00 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:42
2019-05-14 01:000,00 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:43
2019-05-14 02:000,00 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:44
2019-05-14 03:000,04 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:45
2019-05-14 04:000,49 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:46
2019-05-14 05:002,16 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:47
2019-05-14 06:007,98 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:48
2019-05-14 07:0014,82 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:49
2019-05-14 08:0019,98 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:50
2019-05-14 09:0023,51 Facility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:51
2019-05-14 10:0013,49CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:52
2019-05-14 11:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:53
2019-05-14 12:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:54
2019-05-14 13:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:55
2019-05-14 14:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:56
2019-05-14 15:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:57
2019-05-14 16:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:58
2019-05-14 17:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:59
2019-05-14 18:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:60
2019-05-14 19:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:61
2019-05-14 20:000,00CorrectedFacility 3  ABC3Normal timeHourlist 2019-05-14 00:00 - 2019-05-22 23:62

Prevent loading times irrelevant Excel tabs

$
0
0

Hi,

 

I basiclly have the same question as stated in the thread below. I'm looking for a solution to improve performance by preventing the loading times of irrelevant Excel tabs/sheets when adding them to a Power Query.

https://community.powerbi.com/t5/Desktop/Importing-excel-worksheet-among-multiple-worksheets/td-p/76281

 

With 'Get data' or 'New source' im adding mulitple differente Excel spreadsheets to my query. When adding, I'm just selecting a single tab. Every single addition of a new spreadsheet or refresh, all tabs are being imported. This makes my query slow and often crash.

 

Hoping to find a sollution for this inconvenience. Thanks a lot.

 

 

Merging data based on a partial match

$
0
0

Hi there,

 

I have two tables I want to merge in power query:

 

The first table has two colums; a column of partial direct debit bank references, and a second column showing the accounting code each relates to.

 

My second table is essentially a bank statement including a column with the full direct debit references.

 

My aim is for power query to reference the first table, indentify if any of the partial references exist in the bank statetment full references, and then return the accounting code in a new column accordingly.

 

Any help appreciated.

 

Kind regards

 

D

Power Query (M) Select * from A where A.id = B.ID and B.date is last

$
0
0

Hello everybody.

I'm quite new ot PowerBI.

I try and fail doing this in power Query on Power BI.

I try and fail to find a exemple of this.

 

I have a BD Snapshot (that have all the snapshot from lot BDs and Tables).

 

In the Snapshot reference table I have "date_of_snapshot" and "SnapshotID".

And all the tables have a column "SnapshotID"

 

What I want to do, is simple, take the "SnapshotID" related to the  most recent "date_of_snapshot" and get all other query of to load only the data related to this last "SnapshotID".

 

Thanks stranger for your help

Formula.Firewall I

$
0
0

I have an OData query, Stg_ProjectSiteDatabase, that extracts rows from a SharePoint online database, including URLs for subsites. I have a second query that is attempting to add a column, looping through the rows of Stg_ProjectSiteDatabase, calling an OData function to get SharePoint online list ("Issues") data for each subsite using the siteUrl field. However, despite splitting the queries per this article, I am still getting this error:

 

Formula.Firewall: Query 'Issues' (step 'Invoked Custom Function') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.

 

The function 

Here's the second query:

 

let
    Sites = Stg_ProjectSiteDatabase,
    #"Invoked Custom Function" = Table.AddColumn(Sites, "IssuesTable", each GetSPOnlineProjectIssues([SiteURL]))
in
    #"Invoked Custom Function"

I haven't found a solution for this. I tried putting the Stg_ProjectSiteDatabase data in a List, then looping through it to call the function, but same issue.

Faster append query

$
0
0

Hello all!

 

So I'm working on this report that calls from a SQL server. There are millions of rows in each of these tables. The format as follows:

 

dbo_table_for_production_line_1:

part_id | Batch_num | part_weight | <lots of other stuff that we don't care about>

00001  | 919191919  |          350     |

 

 

dbo_table_for_production_line_2:

part_id | Batch_num | part_weight | <lots of other stuff that we don't care about>

00002  | 818181818  |          352     |

 

 

 

dbo_table_for_production_line_3:

part_id | Batch_num | part_weight_D1 | part_weight_D2 | <lots of other stuff that we don't care about>

00003  | 717171717  |          342          |           392          |

 

Now what I do, is I group by the batch number. I need the Min, Max, and Avg of part weight, and if it's on production line 3, I need that second part weight as well.

 

So what I've done is make a query based on each of the dbo_table_for_production_line_X that looks like this:

 

let
    Start_Date =Excel.CurrentWorkbook(){[Name="Start_Date"]}[Content]{0}[Column1],
    End_Date = Excel.CurrentWorkbook(){[Name="End_Date"]}[Content]{0}[Column1],
    Source = Sql.Database("usdvenrpt01", "selfservicebi"),

    dbo_table_for_production_line_1 = Source{[Schema="dbo",Item="dbo_table_for_production_line_1"]}[Data],
    #"Removed Other Columns" = Table.SelectColumns(dbo_table_for_production_line_1,{"WorkOrder", "DoseWeight"}),
#"Filtered" = Table.SelectRows(#"Removed Other Columns", each List.Contains(A_different_table[The_batch_nums_that_need], [Batch_num])), #"Grouped Rows" = Table.Group(#"Filtered", {"Batch_num"}, {
{"Weight Min D1", each List.Min([DoseWeight]), type number},
{"Weight Max D1", each List.Max([DoseWeight]), type number},
{"Weight Avg D1", each List.Average([DoseWeight]), type number},
{"Weight Max D2", each null, type number}
{"Weight Min D2", each null, type number}
{"Weight Avg D2", each null, type number}}) in #"Grouped Rows"

 

 

And for Production Line 3, the agregation functions are set to be Min Max and Average of the other column instead of each null.

Each of these three queries loads really quickly and seems to calculate server side.

 

Now, I then append all three of these tables into one master table using:

let
    Source = Table.Combine({Line_1_query, Line_2_query, Line_3_query})
in
    Source

All of a sudden, the master table takes forever to load. So long that I don't even know how long it takes because after 30 min I decided to stop it.

 

I know that this last query is running client side because my CPU usage goes through the roof when I try to load it, but after filtering to only the Batch_num that I need, there is less than 24 Rows in all three tables combined, so I really don't know why this is throwing a tantrum.


Last n days regardless of year

$
0
0

I need an additional column to say "last7days"

REGARDLESS OF YEAR

if the proper date (not the day number) is in the last 7 days.

 

 

In general words,

for invoiceDate

if this date IsInPreviousNDays(7) regardless of year

then "last7days" else ""

 

P.S. So I am thinking about the same Sunday every year, not about 1st of July every year.

Add Live Exchange Rate Month column

$
0
0

Hi Power BI Team ,

 

Can some please help me ?

 

I have imported Exchnage rate table from Excel data sheet from 01/01/2017 to 01/06/2019 (GBP TO EUR). 

can someone guide me how can i add live exchnage rate by Every 1st of the month which can be updated automatically  ?

 

Thanks.

Transform data from rows to columns when the column headers repeat?

$
0
0

I have data that comes out as shown below (Raw Data), however, all of the ratings are listed in rows based on the individual/customer record they are on. I want each rating to be under the first set of columns (Desired Output). Any ideas? Thanks in advance.

 

Raw Data

Customer IDRating Unique IDRating Added ByDate AddedDate Last ChangedLast Changed By Source Category DescriptionRating Unique ID_1Rating Added By_1Date Added_1Date Last Changed_1Last Changed By_1 Source_1 Category_1 Description_1
100001-592-0000172109dsnyder11/20/201511/20/2018dsnyderFake Source AFake Rating AFake Description AWP_18423_11dsnyder11/20/201511/20/2018dsnyderFake Source AFake Rating AFake Description A
200001-592-0000127359dsnyder4/1/20145/10/2019dsnyderFake Source BFake Rating BFake Description BWP_24657_11dsnyder7/2/201411/12/2018dsnyderFake Source BFake Rating BFake Description B
300001-592-0000126441dsnyder10/7/20135/10/2019dsnyderFake Source AFake Rating AFake Description CWP_24773_11dsnyder7/2/20148/22/2018dsnyderFake Source AFake Rating AFake Description C
400001-592-0000172098dsnyder11/19/20152/19/2019dsnyderFake Source BFake Rating BFake Description AWP_2956_19dsnyder3/2/20162/19/2019dsnyderFake Source BFake Rating BFake Description A
500001-592-0000172130dsnyder11/24/20152/20/2019dsnyderFake Source AFake Rating AFake Description BWP_5392_19dsnyder3/2/20162/20/2019dsnyderFake Source AFake Rating AFake Description B
600001-592-0000172096dsnyder11/19/20158/9/2018dsnyderFake Source BFake Rating BFake Description Cnullnullnullnullnullnullnullnull
700001-592-0000172116dsnyder11/20/20158/29/2018dsnyderFake Source AFake Rating AFake Description Anullnullnullnullnullnullnullnull

 

Desired Output

Customer IDRating Unique IDRating Added ByDate AddedDate Last ChangedLast Changed By Source Category Description
100001-592-0000172109dsnyder11/20/201511/20/2018dsnyderFake Source AFake Rating AFake Description A
200001-592-0000127359dsnyder4/1/20145/10/2019dsnyderFake Source BFake Rating BFake Description B
300001-592-0000126441dsnyder10/7/20135/10/2019dsnyderFake Source AFake Rating AFake Description C
400001-592-0000172098dsnyder11/19/20152/19/2019dsnyderFake Source BFake Rating BFake Description A
500001-592-0000172130dsnyder11/24/20152/20/2019dsnyderFake Source AFake Rating AFake Description B
600001-592-0000172096dsnyder11/19/20158/9/2018dsnyderFake Source BFake Rating BFake Description C
700001-592-0000172116dsnyder11/20/20158/29/2018dsnyderFake Source AFake Rating AFake Description A
1WP_18423_11dsnyder11/20/201511/20/2018dsnyderFake Source AFake Rating AFake Description A
2WP_24657_11dsnyder7/2/201411/12/2018dsnyderFake Source BFake Rating BFake Description B
3WP_24773_11dsnyder7/2/20148/22/2018dsnyderFake Source AFake Rating AFake Description C
4WP_2956_19dsnyder3/2/20162/19/2019dsnyderFake Source BFake Rating BFake Description A
5WP_5392_19dsnyder3/2/20162/20/2019dsnyderFake Source AFake Rating AFake Description B
6nullnullnullnullnullnullnullnull
7nullnullnullnullnullnullnullnull

Referenced Query and Caching question - explanation/confirmation required

$
0
0

Hi,

Before I delve into my question I will declare that I have read the below article but I still have questions regarding my specific scenario:
https://blog.crossjoin.co.uk/2016/11/20/referenced-queries-and-caching-in-power-bi-and-power-query/

 

I have a Power BI report, well only the Power Query (PQ) part is complete at the moment.
The PQ model contains 14 tables. However, only a single table connects to the SQL Server database. This single table's connection (Import Mode) does contain a SQL statement to Query-Fold the statement up-stream to the SQL Server database. 

 

The resulting table name is 'K8 Extract'. The full APPLIED STEPS for this table is Source then Changed Type. No other steps are applied.

 

The 13 remaining tables all reference the 'K8 Extract' table and then go on to do a lot unqiue steps (aggregation, grouping, clauses, etc..) thus resulting in greatly different result-sets - hence the need for 13 separate tables.

 

As the 'K8 Extract' table is the only PQ table that actually connects to the SQL Server database, I am expecting that the SQL Server database to only get queried the once. This is my understanding and aim.

 

However, when I do a data refresh from within the Power BI side of PBI Desktop I see the following:
Query.PNG

At the same time as the above moment in time, I executed a SQL query againt the database the PQ table's SQL statement is running against and it returns the below result:
Stats.PNG

The TEXT column's value of 'SELECT eoft.branch_code....' is the actutal SQL statement that is executed against the SQL Server to return the 'K8_Extract' table.

As I am seeing the 'SELECT eoft.branch_code....' multiple times in the above SQL, and as I am seeing mutiple entries in the Apply query changes box, all referencing the same SQL Server/database, I am led to believe that the SQL Server, that I only want to query just the once, is indeed being queried multiple times.

Am I correct in my observation?

What do I need to do (set/configure) so the source SQL Server/database is only query the once and the other 13 tables just reference the 'K8 Extract' table and do not impact the source SQL Server/database over and over?

Thanks in advance.

Power BI taking ages to apply query changes

$
0
0

Hi all,

 

I have a data set that's similar to the following (but over 4000 rows)

 

Project    Data Category    Data Type    Source    Destination      Time Period    Amount    Index

A             Cash Flow           Baseline       Source1  DestinationA    Q1YYYY          #####      1

B            Expected Value   Actual          Source2  DestinationA    Q2YYYY         #####       2

C            Spend Down       Forecast      Source3  DestinationB    Q1YYYY          #####       3

 

The data that I have in the "Amount" Column is cumulative. I need to make it into specific data, individual for each time period. The code I have to do that is the following:

 

#"test" = Table.AddColumn(#"PreviousStep","Specific", 
    each if [Data Category] <> "Fund Budget" 
    then if [Funding Source] = #"PreviousStep"{[Index]-2}[Funding Source] and [Funding Destination] = #"PreviousStep"{[Index]-2}[Funding Destination] and [Project] = #"PreviousStep"{[Index]-2}[Project] and [Data Category] = #"PreviousStep"{[Index]-2}[Data Category] and [Data Type] = #"PreviousStep"{[Index]-2}[Data Type] 
    then [Amount] - #"PreviousStep"{[Index]-2}[Amount] 
    else if [Data Type] = "Forecast" 
    then [Amount] - Number.From(List.Last(List.RemoveNulls(List.Generate(()=>[x = 0, y = null], each [x] < List.Count(Table.Column(#"PreviousStep", "Amount")), each [x = [x] + 1, y = each if #"PreviousStep"{[x]}[Project] = [Project] and #"PreviousStep"{[x]}[Data Category] = [Data Category] and #"PreviousStep"{[x]}[Data Type] = "Actual" and #"PreviousStep"{[x]}[Funding Source] = [Funding Source] and #"PreviousStep"{[x]}[Funding Destination] =[Funding Destination] then #"PreviousStep"{[x]}[Amount] else null], each [y])))) 
    else [Amount] 
    else [Amount])

Basically, the code is supposed to work as follows. As the query creates a new column, it checks first to see the Data Category- anything that's part of a "Fund Budget" does NOT get unfolded into a specific number, it just stays in cumulative form. Next, it checks to see if the Data Type, Category, Source, and Destination match between the row in question and the previous row (all of the data is listed in chunks ordered by time period). If they do, the specific amount is calculated just by subtracting the cumulative amount from the previous time period from the cumulative amount of the current time period.

 

The next part is the tricky bit. For Forecasted data, the specific period amount for the first point (i.e. the data that doesn't match the immediate precious row) should be calculated by subtracting out the cumulative from the Actual data of the previous time period. My idea of how to do this involves using List.Generate to separate out the Actual data that matches the Data Category, Source, and Destination of each of the Forecast initial points and grabbing the last of that list to subtract from the Forecast amount. So far, the code seems to do what it's supposed to.

 

But when I click "Close & Apply" the model takes ages to actually update (as in 2 hours and counting). It didn't do this until I added the Forecast specific if-then-else statement, and I understand that adding a bit more time to the update and apply process (it's a pretty complex generation trick, after all) but 2 hours? I find that a little ridiculous.

 

So do you all see something that maybe I missed that's making this way more difficult than it needs to be? Is there a way to speed up this process? Unfortunately I am restricted to using power query for this- I thought about moving it into Python initially but due to restrictions from the top brass I have to do all of my transformations in Power BI.

 

Thanks,

Jason

Excel - Power Query: VBA for looping through slicers created using data model. Help!

$
0
0
All - this is in RE: Excel VBA. I am looking for looping through slicer selection and print PDF's. my code does work for standard pivots, but it does not work when using it on PowerPivot which is what I am looking for.

Can anyone please shed some light on how to turn the below so it works in powerpivot? (slicer from power pivot source data)

 

Let me know any questions - looking forward to hearing any tips Smiley HappySmiley Happy

 

Thanks! Smiley Happy

 

 

 

 

Option ExplicitSub ExportPDFs()Dim sI As SlicerItem, sI2 As SlicerItem, sc As SlicerCacheDim fname$Set sc = ActiveWorkbook.SlicerCaches("Slicer_Date")With scForEach sI In sc.SlicerItemsIf sI.HasData =TrueThen        sc.ClearManualFilterForEach sI2 In sc.SlicerItemsIf sI.Name = sI2.Name Then sI2.Selected =TrueElse: sI2.Selected =FalseNext        Debug.Print sI.Name
        fname = sI.Caption &" "& Format(Date,"MM-DD-YYYY")&" "&"Report"        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=FalseEndIfNext    ActiveWorkbook.SlicerCaches("Slicer_Year").ClearManualFilter
    MsgBox "Reports Saved"EndWithEndSub

Azure blob - Account Key vs. Anonymous

$
0
0

Hello all,

 

I apologize if the answer to this question is too obvious, but I seem to be missing something.

 

When using the Azure blob connector in PBI, you are presented with the option of anonymous authentication, or account key. I understand that the drawback to using an account key is a lack of granular security controls, but even in testing pulling images down from blob storage set to private access with an account key, the connection does not work. Is anonymous authentication the only supported method for serving images to PowerBi from blob storage? If I am not mistaken, this would mean that any images you want to use in PBI would also be publicly accessible.

 

Any help in understanding is greatly appreciated, 

 

Thank you!


Pseudo code

$
0
0

Hi 

 

I have a pseudo code which I need to put into Power bi. As Im new to both I need some help with putting the code in Pbi

 

The energy reading im pulling out of the database vary from 2-6 seconds per minute. I need to fill in th egaps so that their are readings every minute to work out the KWH (kilo watts/hour)

 

Array  Readings[Num_Energy_Readings]

Array CorrectedReadings[Num_Energy_Readings]

Count =0

EnergyAdjust = 0

TimeOffset=Readings[0]              ‘ Set energy to 0 at the first time required to clear previous energy

CorrectedReadings[0]=Readings[0]-TimeOffset    ‘ Load first readings

For count=1 to count = Num_Energy_Readings

{

                If Readings[count] <  Readings[count-1]

                {

                                EnergyAdjust=EnergyAdjust + Readings[count-1]

                }

                CorrectedReadings[count]=Readings[count]+EnergyAdjust[]-TimeOffset

}

What is the best way to apply Nested Relationship same as SQL Statements?

$
0
0

Hello,

 

I'm trying to achieve the following SQL Statement's result into Power BI.

SELECT Coalesce(c.name, 'Andre Transportører') AS name, 
       Count(*)                                 Bookings, 
       Coalesce(t2.totinv, 0)                   AS Invoiced, 
       Coalesce(t2.freightcost, 0)              AS InvFreight, 
       Count(*) - Coalesce(t2.totinv, 0)        AS NotInvoiced, 
       Coalesce(t2.freightcost, 0) / Coalesce(t2.totinv, 1) * ( Count(*) - 
       Coalesce(t2.totinv, 0) )                 AS Avsetning 
FROM   carriers c 
       right join tplbookings t 
               ON c.id = t.carrierid 
       left join (SELECT i.carrierid, 
                         Coalesce(Count(*), 0)                        AS TotInv, 
                         SUM(Coalesce(w.netamount, 0) 
                             + Coalesce(w.totalamountfromcharges, 0)) AS 
                         FreightCost 
                  FROM   waybills w 
                         inner join invoices i 
                                 ON w.invoiceid = i.id 
                  WHERE  i.invoicestatus <> 'Draft' 
                         AND i.customerid = 1067 
                         AND w.departuredate BETWEEN 
                             '2019-06-01' AND '2019-06-30' 
                  GROUP  BY i.carrierid) t2 
              ON t.carrierid = t2.carrierid 
WHERE  t.customerid = 1067 
       AND departuredate BETWEEN '2019-06-01' AND '2019-06-30' 
GROUP  BY c.name, 
          t2.totinv, 
          t2.freightcost 
ORDER  BY Count(*) DESC

I 'm getting the following end result with above SQL Statement.

Screenshot_3.png

Now, I have tried to apply the same relationship within my Power BI tables and and take all the parameters from the where conditions as a slicer in Power BI and Select statement as a column from table. Still I'm not getting the correct result.

 

What I'm missing here in relationship? Or what is the best way to achieve this type of result in Power BI?

Screenshot_4.png

 

Any help really appriciated !


Thanks

Nested table issue with TransformColumns

$
0
0

Hello Experts,

 

I would like to transform following tables into the same cell in this format:

“Prop1=wood,abc;Prop2=red,red2;Prop3=ok,ok2;Prop4=400,ooo1,ooo2”

 

(I was somehow able to transfor from prop1-3, but get stuck at prop4)

Can you please help me with the proper syntax?

 

 

Input xml sample:

 

<?xml version="1.0" encoding="UTF-8"?>
<documents>
<document>
<property>
<name>prop1</name>
<subprop>
<value1>wood</value1>
<value2>abc</value2>
</subprop>
</property>
<property>
<name>prop2</name>
<subprop>
<value1>red</value1>
<value2>red2</value2>
</subprop>
</property>
<property>
<name>prop3</name>
<subprop>
<value1>ok</value1>
<value2>ok2</value2>
</subprop>
</property>
<property>
<name>prop4</name>
<subprop>
<value1>400</value1>
<value2>
<value3>ooo1</value3>
<value4>ooo2</value4>
</value2>
</subprop>
</property>
</document>
</documents>

 

 

 

Thank you very much,

Best Regards,

Zefi

Is it possible to have an If function in another If function

$
0
0

Hi 

I'm interested in moving this DAX formular into Power Query: 

S1 = IF(IF('STATUS 1'[t2s1q4] >2;1;0)+If('STATUS 1'[t2s1q5] >2;1;0)+If('STATUS 1'[t2s1q11] >2;1;0)+If('STATUS 1'[t2s1q12] >2;1;0)+if('STATUS 1'[t2s1q13] >2;1;0)+if('STATUS 1'[t2s1q14] >2;1;0)+if('STATUS 1'[t2s1q15] >2;1;0) >2;TRUE;FALSE)

It is an If function with multiple If functions within it: If(if + if + if ..) then, else - I am using it to measure If different test scores are above a certain limit (>2) and finally If >2 of these tests are above that limit. All the STATUS tables range from 1-5.

Is this possible in Power Query, as it is in DAX?

I'm fairly new to M, so this might be a newbie question. I would appreciate any help!


Finding First Name or Last name using DAX like @Username

$
0
0

Hi, 

I understand that PowerBI records name of all the users who are logged into the app. I am using RLS on  

I want to develop a greeting where I greet them with their name such as:

 

Good Afternoon Usman

 

Is it possible?

I found this solution but it doesn't work. 

 

Greeting1 = 
VAR user = USERNAME()
VAR display = LOOKUPVALUE(Table1[User],Table1[Email],user)
VAR hour = HOUR(NOW())
VAR minute = MINUTE(NOW())
VAR prefix = SWITCH(
                    TRUE(),
                    hour<12,"Good morning ",
                    hour>=12 && hour<17,"Good afternoon ",
                    "Good evening "
             )
RETURN CONCATENATE(prefix,display)

 

Viewing all 31433 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>