Combine 2 values in DAX - powerbi

I've got 2 columns:
Year and Quarter.
And in the third column I need to show info from these 2 fields in such way "Q1 23" and so on..
How to make such formula in QY column?

Here you go.
QY = "Q" & 'Table'[Q] &" " & RIGHT('Table'[Y],2)

Related

How to dynamically add rows to column in power bi/power query

I'm facing a challenge in power bi where I need to join Table 1 & Table 2 but the catch is Table 2 needs to be pivoted before joining.
Input:
Table 1
Table 2
Expected Output:
How to build the output table when the Table 2 rows will be increasing daily
Your desired result needs a combination of Unpivot, Merge and Pivot steps.
You can follow the following steps:
Convert the Date column to Text type.
Unpivot columns Sales in KG & Sales in Amount from Table 2 - it will create 2 columns called Attribute & Value
Merge columns Date & Attribute to create a new column (lets call it columnHeaders) - this will be in the format - 1/3/22 Sales in KG, 1/3/22 Sales in Amount ...
Merge Table 1 into Table 2 and expand the Product Name column
Now you will have 4 columns - Product Code, columnHeaders, Value, & Product Name
Pivot columnHeader using the Value column for values
You should have your desired result.
I dont know why you try to unpivot your table. Just use a Matrix visualization:
Model relationship:
Imput data + output:
sum of kg = CALCULATE(sum(Table2[Sales in kg]))

Calculated Column for first 5 working days in each month

I wanted to do calculated column in my calendar table in Power BI. The calculated column should show "1" for the first 5 working days in each month in the calendar table, the rest of the days should be "0" . I tried to come out with the formula shown below
tick = CALCULATE(COUNT('Calendar'[Weekend - weekday]), 'Calendar'[IsWorkingDay] = TRUE)
But it shows "1" for all the working days but the desire output is the first 5 working days of each month. Anyone could help me
Suppose this is your original table with new column for Weekday-weekend, you can calculate the new column to display 0 for first five working days using rankx & If, followed by 0 and blank for other case, here is the dax formula:
Remark: Both 1 and 0 need to with quotation mark, as using with "" without convert to string will cause Data is variant type error.
tick1 =
var rank1 = RANKX(FILTER(Sheet1,Sheet1[Weekday-Weekend] = "Weekday" && Sheet1[Period] = EARLIER(Sheet1[Period]) ),Sheet1[Day],,ASC)
return
IF(Sheet1[Weekday-Weekend] = "Weekday" && rank1 >=1 && rank1 <=5, "1",
IF(Sheet1[Weekday-Weekend] = "Weekday", "0",""))
The table with add column

Remove weekends in a formula

I want to remove weekends from a calculated column calculation. I am having a formula which calculate daily target:
Daily MAL Target = [MAL_Qtarget_A] /
(ENDOFQUARTER(Marketing_targets_MALMEL[Date]) -
ENDOFQUARTER(PREVIOUSQUARTER(Marketing_targets_MALMEL[Date])))
In the marketing Targets table thers a seperate column to identify whether the date is working day or weekday as 1 and 0.
IsWorkDay = SWITCH(WEEKDAY([Date]),1,0,7,0,1)
I want to add "IsWorkingDate=1" to the above Daily Mal Target formula. It is a calculated column. I have tried so many ways but could not do it.
Can anyone help me on this?
You can use this DAX expression to check for weekdays:
= IF(OR(WEEKDAY([Date]) = 1, WEEKDAY([Date) = 7), "Calculation for Weekdays", "Calculation for Mo to Fr")
If it's a calculated column, you can use an if condition to make the value 0 or blank for weekends:
Daily MAL Target = IF(WEEKDAY(Marketing_targets_MALMEL[Date]) in {1,7},
BLANK(),
([MAL_Qtarget_A] /
(ENDOFQUARTER(Marketing_targets_MALMEL[Date]) -
ENDOFQUARTER(PREVIOUSQUARTER(Marketing_targets_MALMEL[Date]))))
Hope this helps.

How to pass slicer range to groupby value

I want to find the sum of values groupby name according to time slicer visual in the powerBI
How can I achieve this?
name date value
Kelvin 10/01/1989 3
Peter 02/05/2018 4
Kelvin 02/02/2012 5
James 02/07/2014 2
Peter 04/01/2012 2

Creating a calculated table by passing a measure or parameter

I have a requirement where I have a data like this,
Date Name Age
1-1-2018 A 1
2-2-2018 B 1
3-3-2018 B 1
6-6-2018 C 2
7-7-2018 B 6
I am trying to give a slicer to the user to select the required number of months from the last month.
So to do that, I am using a calculated column like this:
Month Year = DATEDIFF((Table1[Date]), TODAY(), MONTH) + 1
So that changes the data to something like this:
Date Name Age MonthYear
1-1-2018 A 1 7
2-2-2018 B 1 6
3-3-2018 B 1 5
6-6-2018 C 2 2
7-7-2018 B 6 1
The user selects the Month Year from the Slicer.
For example, when he selects 2, I want to display the last 2 months records in the table.
Expected Output:
Date Name Age
6-6-2018 C 2
7-7-2018 B 6
This works for me if I hardcode it like this:
Calculated Table = CALCULATETABLE(Table1,
FILTER(Table1, OR(Table1[MonthYear] > 2, Table1[MonthYear] = 2)))
But it fails when I try to pass the value in the place of 2 dynamically through a measure using SelectedValue function.
Calculated columns and calculated tables cannot reference a slicer value since they are only computed when you load your data.
If you want to apply this filtering to a visual, I'd suggest creating a separate table for your slicer. For example, you could use Months = GENERATESERIES(1,12) and then rename the column Months as well.
Use the Months[Months] column for your slicer and then create a measure which references it to filter your table/matrix visual.
Filter = IF(SELECTEDVALUE(Months[Months]) >= MAX(Table1[Month Year]), 1, 0)
Then use that measure in your Visual level filters box: