I have a dataset in Power BI like this
ID DATE
1 06/24/2016
1 06/24/2017
1 06/24/2018
2 08/08/2017
2 08/08/2016
3 12/12/2015
I would like to create a calculated column with DAX, in which i have to calculate the latest date for every index, but I am only able to get the latest date of all the dataset or the same date for every row.
The output should be this:
ID DATE MAXDATE
1 06/24/2016 06/24/2018
1 06/24/2017 06/24/2018
1 06/24/2018 06/24/2018
2 08/08/2017 08/08/2017
2 08/08/2016 08/08/2017
3 12/12/2015 12/12/2015
MAXDATE = CALCULATE(MAX(Table1[Date]);FILTER(Table1;Table1[ID]=EARLIER(Table1[ID])))
Related
Hello I am a beginner in Power BI and would need your help.
I have a data at my end and I need to have Cumulative count of my data based on Month.
ID
Code
DATE
GENDER
Cumulative Count
1
A
5/30/2022
M
1
2
A
5/31/2022
F
3
3
A
5/31/2022
M
3
4
A
6/1/2022
F
2
5
A
6/1/2022
F
2
6
A
6/2/2022
M
3
Cumulative Count column above is the output that I am expecting to create in Power BI. Here I have created it manually.
On 30th May total count was 1 then on 31st May count was 2 hence value is 3. Once the month ends and new month starts it should start from 0 and hence on 1st June there are 2 observation and hence total count is 2 and so on.
Try this
CALCULATE(
COUNTROWS('Table')
,ALLEXCEPT('Table','Table'[Date])
,DATESMTD('Table'[Date])
)
I have two tables in Power BI as follows:
COUNTRIES
COD COUNTRY
1 BRAZIL
2 ARGENTINA
3 CHILE
4 BRASIL
5 COLOMBIA
6 ARGENTINA
7 URUGUAI
SALES
COD DATE
1 2021-01-02
2 2021-10-01
3 2019-09-04
1 2018-07-05
7 2019-04-10
There's a relationship between the two tables, on the COD column.
I need to count how many countries (column "COUNTRY" from the table "COUNTRIES") have a status CHURN. It's considered CHURN when their latest order from the table "SALES" is more than 180 days, using today as a reference.
I know that I need to group by the MAX date per country, do a DATEDIFF, and then do a COUNT. I've tried using ALL and SUMMARIZE, but I haven't found a way to solve this problem.
Are you able to add a calculated column to store the max sales date for each country in your COUNTRIES table? Either in Power BI or directly in your database. If so, here's one solution with 2 steps.
Create a MaxSalesDate column in your COUNTRIES table. DAX for a calculated column below:
MaxSalesDate =
VAR COD = COUNTRIES[COD]
RETURN MAXX(FILTER(SALES, SALES[COD] = COD), SALES[DATE])
Create a measure that counts the number of MaxSalesDate values that are older than 180 days old:
CountCHURN = COUNTX(COUNTRIES, IF(DATEDIFF(COUNTRIES[MaxSalesDate], TODAY(), Day) > 180, 1))
I have a "data" table and there is an column "period" -
period
1 year
3 year
1 year
2 year
3 year
3 year
I want my output to be -
year
count
1 year
2
2 year
1
3 year
3
please help me to get this output
Create a new table:
newTable = SUMMARIZE(
Tabelle, /// select table
Tabelle[period], ///
"Count", /// give name for value col
COUNT(Tabelle[period])) /// define function
Output:
In Power BI I have some duplicate entries in my data that only have 1 column that is different, this is a "details" column.
Basically, when I sum up my Value column on a Power BI card, I want it to filter IsActive = 1 and sum for each unique name, so in this case:
Total= 10 + 7
Is there any way I can filter this with a DAX formula?
Assuming your table can also have a row with the same value of another row but a different name, and a row where Details column doesn't always include "Feature 1"
Name Values Details IsActive
Item 1 10 Feature 1 1
Item 1 10 Feature 2 1
Item 2 15 Feature 1 0
Item 3 7 Feature 1 1
Item 3 7 Feature 2 1
Item 3 7 Feature 3 1
Item 4 10 Feature 1 1
Item 5 10 Feature A 1
then we should use the Name column an write something like follows
Total =
CALCULATE(
SUMX( SUMMARIZE( T, T[Name], T[Values] ), T[Values] ),
T[IsActive] = 1
)
You can create a calculated column wherein you rank the rows based on the occurrence via M-query as provided in the below link :
https://community.powerbi.com/t5/Desktop/How-to-add-Row-number-over-partition-by-Customer-DAX-or-M-query/td-p/566949
Once the calculated column is done, you can achieve your result based on the below measure :
sum(value) where IsActive=1 and calculatedColumn=1 via on Filter DAX
It doesn't appear that the first occurrence is relevant, so you can just write a measure to sum distinct values.
SUMX (
CALCULATETABLE (
VALUES ( Table1[Value] ),
Table1[IsActive] = 1
),
Table1[Value]
)
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: