Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have two tables, one is an orders table with an order date and the other is a semester table with a semester start date. I am wanting to evaluate how close the order date is to the semester start date but I need to figure what the closest semester start date is.
So in the example below, the yellow column would be calculated in the Orders Table. The first order has an order date of 1/1/2022 and the closest start date is 1/6/2022 so there you go. I would also be ok if this result wasn't the date, bit the SemesterID. PBIX file here.
Solved! Go to Solution.
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new column.
Desired result CC =
VAR currentschoolid = OrderTable[SchoolID]
VAR currentorderdate = OrderTable[OrderDate]
VAR semesterdatedifftable =
ADDCOLUMNS (
FILTER ( SemesterIDTable, SemesterIDTable[SchoolID] = currentschoolid ),
"@orderdate", currentorderdate
)
VAR datediffcolumn =
ADDCOLUMNS (
semesterdatedifftable,
"@diff", ABS ( DATEDIFF ( [@orderdate], SemesterIDTable[SemesterStartDate], DAY ) )
)
VAR datediffmin =
MINX ( datediffcolumn, [@diff] )
VAR filtermin =
FILTER ( datediffcolumn, [@diff] = datediffmin )
RETURN
MAXX ( filtermin, SemesterIDTable[SemesterStartDate] )
Desired result semesterID CC =
VAR currentschoolid = OrderTable[SchoolID]
VAR currentorderdate = OrderTable[OrderDate]
VAR semesterdatedifftable =
ADDCOLUMNS (
FILTER ( SemesterIDTable, SemesterIDTable[SchoolID] = currentschoolid ),
"@orderdate", currentorderdate
)
VAR datediffcolumn =
ADDCOLUMNS (
semesterdatedifftable,
"@diff", ABS ( DATEDIFF ( [@orderdate], SemesterIDTable[SemesterStartDate], DAY ) )
)
VAR datediffmin =
MINX ( datediffcolumn, [@diff] )
VAR filtermin =
FILTER ( datediffcolumn, [@diff] = datediffmin )
RETURN
MAXX ( filtermin, SemesterIDTable[SemesterID] )
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new column.
Desired result CC =
VAR currentschoolid = OrderTable[SchoolID]
VAR currentorderdate = OrderTable[OrderDate]
VAR semesterdatedifftable =
ADDCOLUMNS (
FILTER ( SemesterIDTable, SemesterIDTable[SchoolID] = currentschoolid ),
"@orderdate", currentorderdate
)
VAR datediffcolumn =
ADDCOLUMNS (
semesterdatedifftable,
"@diff", ABS ( DATEDIFF ( [@orderdate], SemesterIDTable[SemesterStartDate], DAY ) )
)
VAR datediffmin =
MINX ( datediffcolumn, [@diff] )
VAR filtermin =
FILTER ( datediffcolumn, [@diff] = datediffmin )
RETURN
MAXX ( filtermin, SemesterIDTable[SemesterStartDate] )
Desired result semesterID CC =
VAR currentschoolid = OrderTable[SchoolID]
VAR currentorderdate = OrderTable[OrderDate]
VAR semesterdatedifftable =
ADDCOLUMNS (
FILTER ( SemesterIDTable, SemesterIDTable[SchoolID] = currentschoolid ),
"@orderdate", currentorderdate
)
VAR datediffcolumn =
ADDCOLUMNS (
semesterdatedifftable,
"@diff", ABS ( DATEDIFF ( [@orderdate], SemesterIDTable[SemesterStartDate], DAY ) )
)
VAR datediffmin =
MINX ( datediffcolumn, [@diff] )
VAR filtermin =
FILTER ( datediffcolumn, [@diff] = datediffmin )
RETURN
MAXX ( filtermin, SemesterIDTable[SemesterID] )
@awitt , a new column in table1
minx(filter(Table2, Table2[semesterDate] >= Table1[OrderDate] && Table2[schoolID] = Table1[SchoolID]), Table2[semesterDate])
So this worked when the orderdate was before the start date. But in a case where something was ordered the day after start, this column is picking up not that start day the day before but rather the next start date which might be months away.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
67 | |
65 | |
56 | |
39 | |
27 |
User | Count |
---|---|
85 | |
59 | |
45 | |
43 | |
38 |