cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
akfir
Helper V
Helper V

Calculated column of previous value by date & customer

akfir_0-1646920667536.png

Hi guys,
i wish to add a calculated column as in E column above which calculates the previous grade (by date and customer). please note that in my table i have rows which do not hold a grade and presenting blank value.

3 ACCEPTED SOLUTIONS

We may reduce the number of columns if you have too many. For now please try this

Previous Grade =
VAR CurrentDate = 'Table'[Date]
VAR T1 =
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Customer Code] ) )
VAR T2 =
    FILTER ( 'T1', [Date] < CurrentDate )
VAR T3 =
    TOPN ( 1, 'T2', [Date] )
VAR T4 =
    SELECTCOLUMNS ( 'T3', "@PGrade", [Grade] )
RETURN
    Result

View solution in original post

 

Previous Date =
VAR CurrentDate = 'Table'[Date]
VAR T1 =
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Customer Code] ) )
VAR T2 =
    FILTER ( 'T1', [Date] < CurrentDate )
VAR T3 =
    TOPN ( 1, 'T2', [Date] )
VAR Result =
    SELECTCOLUMNS ( 'T3', "@Date", [Date] )
RETURN
    Result

 

View solution in original post

Try this

First Purchase Channel =
CALCULATE (
    VALUES ( Data[Purchase Channel] ),
    ALLEXCEPT ( Data, Data[Customer Code] ),
    Data[Date] = Data[First Purchase Date]
)

View solution in original post

26 REPLIES 26

thanks!
and if i wish to add a column of its first purchase channel related to this first purchase date?

Try this

First Purchase Channel =
CALCULATE (
    VALUES ( Data[Purchase Channel] ),
    ALLEXCEPT ( Data, Data[Customer Code] ),
    Data[Date] = Data[First Purchase Date]
)

Hi my friend,
i have this kind of data table and i wish to build the correct measures/calculations in order to show this kind of bar chart.
i actually need to calculate how many customers were sent X messages successfully.
can you please assist me with the right DAX for it?

thanks in advance.
image.png

is there a way doing this on Power Query and not DAX?

akfir_0-1646946591303.png

 

johnt75
Super User
Super User

Prev grade = 
var currentDate = 'Grades'[Date]
return SELECTCOLUMNS( CALCULATETABLE(
TOPN( 1, 'Grades', 'Grades'[Date]), ALLEXCEPT(Grades,Grades[Customer code]),
'Grades'[Date] < currentDate ),
"@prev grade", 'Grades'[Grade] )

Create this as a new column

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors