PowerBi - Weeknumber not in the correct order - powerbi

I'm new to PowerBi and i'm running into the following problem:
Weeknum + year are not shown in the correct order. See the following screenshots:
I've concatenate weeknumber with year based on a column called "PublishDate"
This is my dax query for weeknum:
Weeknum = YEAR ( [PublishDate] ) & "" & WEEKNUM ( [PublishDate], 2 )
I do notice that 1 till 9 are not shown with a 0 infront of it. Could this be causing this?

I agree with getting the '0' in the right place. Once you change the data type from text to a number, if that '0' in't there, it will be out of order as well.
I prefer editing the query and changing the data type from the beginning:
Finding the column that needs a data type change and modifying it there:
[
You can change it from text to whole number.

The problem is that the values are being sorted in alphabetical order, because they are of datatype text. So yes, the fact that '9' does not have a '0' in front of it, does cause your problem. You can solve this by changing the format of the WEEKNUM function like this (also you do not need & "" &):
Weeknum = YEAR ( [PublishDate] ) & FORMAT(WEEKNUM ( [PublishDate], 2 ),"00")

Related

I want to create a column with a custom function based on another column on Power Query

The function searches a value in a Excel workbook and gives me a cetain info.
It Works like this:
Excel
Column1 Column2
A 1
B 2
C 3
My Function ("A") - Output > 1
My Function ("B") - Output > 2
My Function ("C") - Output > 3
Now i got a table in Power Query, like this:
Power Query
ColumnX
B
C
A
A
I want to create another column on the power query table using my function. And as input i want to use de column X.
But right now, it isn't working.
PS. the output of the function is a M Formula(Ex:. [Column10] * [Column11])
The line of code that i'm using is:
= Table.AddColumn(#"Tipo Alterado", "Formula", each Expression.Evaluate(MyFunction([ColumnX]),#shared))
Already tried without de enviroment variable and it didn't work.
PS2: If i write the code as if it was only one input at columnX it works!
The code looks like this:
= Table.AddColumn(#"table1", "Formula", Expression.Evaluate(MyFunction("B"),#shared))
Someone knows how to make it work ?
Updated
You can remove all of the Expression Evaluate calls. (The second step looks like you're passing the result of a function, but Table.AddColumn needs a function definition )
PS. the output of the function is a M Formula(Ex:. [Column10] * [Column11])
In that case you may want to pass the row as the argument, instead of the specific column. It depends on what you're doing.
let
Source = ...,
MyFunction = (row as record) =>
row[Column10] * row[Column11],
#"Add Column2" = Table.AddColumn(
Source, "Column2",
(row) => MyFunction( row ),
type any // replace with the right type
)
in
#"Add Column2"
Original Answer
I think what you're asking for is a simple mapping. You can skip the Expression.Evaluate
= Table.AddColumn(
Source, "Column2",
(row) =>
MyFunction( row[Column1] ),
type any
)

How to merger these two records ino one row removing Null value in Informatica using transformation. Please see the snapshot for scenario

enter image description here
Input-
Code value Min Max
A abc 10 null
A abc Null 20
Output-
Code value Min Max
A abc 10 20
You can use an aggregator transformation to remove nulls and get single row. I am providing solution based on your data only.
use an aggregator with below ports -
inout_Code (group by)
inout_value (group by)
in_Min
in_Max
out_Min= MAX(in_Min)
out_Max = MAX(in_Max)
And then attach out_Min, out_Max, code and value to target.
You will get 1 record for a combination of code and value and null values will be gone.
Now, if you have more than 4/5/6/more etc. code,value combinations and some of min, max columns are null and you want multiple records, you need more complex mapping logic. Let me know if this helps. :)

PowerBI empty values row not displayed

I have a confusing mystery...
Simple DIVIDE formula works correctly. However blank rows are not displayed.
I attempted a different method using IF, and now the blank row is correctly displayed.
However this line is only displayed if I include the IF formula (which gives a zero value I don't want).
Formula 1:
Completion % =
DIVIDE(SUM(Courses[Completed]),SUM(Courses[Attended]),BLANK())
Formula 2:
Completion % with IF =
IF(SUM(Courses[Attended])=0,0,DIVIDE(SUM(Courses[Completed]),SUM(Courses[Attended])))
With only the DIVIDE formula:
Including the IF formula:
It appears that Power BI is capable of showing this row without error, but only if I inlude the additional IF formula. I'm guessing it's because there is now a value (0) to display.
However I want to be able show all courses, including those that have no values, without the inaccurate zero value.
I don't understand why the table doesn't include these lines. Can anyone explain/help?
The point is very simple, by default Power BI shows only elements for which there is at least one non-blank measure.
The DIVIDE operator under-the-hood execute the following:
IF(ISBLANK(B), BLANK(), A / B))
You can change its behaviour by defining the optimal parameter in order to show 0 instead of BLANK:
DIVIDE(A, B, 0) will be translated in the following:
IF(ISBLANK(B), 0, A/B))
Proposed solution
Those mentioned avobe might all be possible solutions to your problem, however, my personal suggestion is to simply enable the option "show item with no data" in your visualization.
While DIVIDE(A, B, 0) will return zero when when B is zero or blank, I think a blank A will still return a blank.
One possibility is to simply append +0 (or prepend 0+) to your measure so that it always returns a numeric value.
DIVIDE ( SUM ( Courses[Completed] ), SUM ( Courses[Attended] ) ) + 0

PARSE_DATETIME formatting with day of year

Having an issue with the PARSE_DATETIME function in BigQuery used with the day of year (%j) formatting element. The function seems to ignore the day of year element.
Eg.
select PARSE_DATETIME("%Y%j", "2013243")
returns 2013-01-01T00:00:00, lacking day of year component.
However the reverse function with the same date formatting elements works as expected:
select FORMAT_DATETIME("%Y%j", "2013-02-02T00:00:00")
returns: 2013033
Bug? or user error?
Cheers
I think that this is a bug that could be fixed! there is no logic in it working one way but not opposite!
Meantime, you can use below to achieve goal
#standardSQL
CREATE TEMP FUNCTION PARSE_DATETIME_WITH_DAYS(x STRING) AS (
DATETIME_ADD(PARSE_DATETIME('%Y%j', x), INTERVAL CAST(SUBSTR(x, -3) AS INT64) - 1 DAY)
);
SELECT PARSE_DATETIME_WITH_DAYS('2013243')
with result -
Row f0_
1 2013-08-31T00:00:00
Not a bug, neither an error! PARSE_DATETIME uses a format_string and a STRING representation of a DATETIME to return a DATETIME -> "2013243" does not represent a DATETIME string, not a DATE...
To achieve what you are looking for first get the day number - 1 and add it to date (first day of the year) and format the output to DATETIME
SELECT DATETIME(DATE_ADD((SELECT PARSE_DATE("%Y%j", "2013243")), INTERVAL CAST((SELECT SUBSTR("2013243", -3)) AS INT64) -1 DAY));
Output:
2013-08-31T00:00:00

How to write a complex calculated field in Data Studio with regex?

I have been trying to make this regular expression REGEX filter work in Google Data Studio. It is supposed to do the following
Check the field "src_id" and COUNT all the values containing "widget".
Check the field "Page" and COUNT all the values starting with a "/" and ending with "/start".
Check the field "real_title" and NOT COUNT any value containing "-".
I have tried using the code below but it's not providing the correct result:
COUNT(CASE WHEN REGEXP_MATCH(src_id, "^widget" ) THEN 1
WHEN REGEXP_MATCH(Page, ".*(/start)$") then 1
WHEN REGEXP_MATCH(real_title, "^[^-]") then 1
ELSE 0 END)
I expect the result to "52" but it's giving me "582. I need help to spot what I'm doing wrong.
The problem is your count() - it is counting all the entries including zeroes.
either use sum() or just use the case statement and sum where you want it .
Examples
TestField1
COUNT(CASE WHEN REGEXP_MATCH(Page Title , "^How.*" ) THEN 1
ELSE 0 END)
This returns 58 - the number of page titles on my site.
TestField2
Sum(CASE WHEN REGEXP_MATCH(Page Title, "^How.*" ) THEN 1
ELSE 0 END)
This returns 7 - the number of titles on the site that start with "How"
You really don't need the sum() function in most cases because you can sum the field in the places you need it.