Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Partitioning Data by Date using Power Query

Hello,

 

I'm currently looking to implement partitioning on a data model with several large fact tables in it, I've replicated the partitions in Tableau Editor but I need to add some MQuery into each to only add CY, PY, P2Y into the respective partitions. I've not really done much with Mquery until now so unsure how to do this in M.

 

I'm havinf to do it this way and not via SQL Server and Incremental refresh because these Fact tables are loaded from a CSV file thats regenerated nightly so need to do this in M.

 

Any help would be greatly appericated. 

 

Thanks 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

From what I understand of the Table.Partition function (not a huge amount), it only accepts a single hash function with which to evaluate all partitions i.e. it can't make three distinct assessments on the same table to partition.

Do you specifically have to output a list of tables, or could you just use three distinct table queries to import into Tableau?

If this is feasible, you can either import your table into PQ three times and filter them as required, or import once and reference this query three times to the same effect.

 

The table filters you would need to apply in M are as follows:

// CY filter
Table.SelectRows(
  previousStep,
  each Date.IsInCurrentYear([yourDateColumn])
)

// PY filter
Table.SelectRows(
  previousStep,
  each Date.IsInPreviousYear([yourDateColumn])
)

// P2Y filter (presume this means 'two years ago')
Table.SelectRows(
  previousStep,
  each [yourDateColumn] >= Date.StartOfYear(Date.AddYears(Date.From(DateTime.LocalNow()), -2))
and [yourDateColumn] <= Date.EndOfYear(Date.AddYears(Date.From(DateTime.LocalNow()), -2))
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hello

 

I'm in Tableau Editor and I'm looking to create 3 partitions in a Fact Table (see below example) and then have some MQuery in this that only puts the CY in one partition, the some in Previous Year in another and Year on 2 Year in the last.

Forks85_0-1642606377650.png

 

I think I need to use the Table.Partition M Function but unsure if this'll work and how to use it ? 

Hi @Anonymous ,

 

From what I understand of the Table.Partition function (not a huge amount), it only accepts a single hash function with which to evaluate all partitions i.e. it can't make three distinct assessments on the same table to partition.

Do you specifically have to output a list of tables, or could you just use three distinct table queries to import into Tableau?

If this is feasible, you can either import your table into PQ three times and filter them as required, or import once and reference this query three times to the same effect.

 

The table filters you would need to apply in M are as follows:

// CY filter
Table.SelectRows(
  previousStep,
  each Date.IsInCurrentYear([yourDateColumn])
)

// PY filter
Table.SelectRows(
  previousStep,
  each Date.IsInPreviousYear([yourDateColumn])
)

// P2Y filter (presume this means 'two years ago')
Table.SelectRows(
  previousStep,
  each [yourDateColumn] >= Date.StartOfYear(Date.AddYears(Date.From(DateTime.LocalNow()), -2))
and [yourDateColumn] <= Date.EndOfYear(Date.AddYears(Date.From(DateTime.LocalNow()), -2))
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Not sure what you mean by 'partition' the fact table. Do you mean you want separate fact tables for CY/PY etc. or that you just want to be able to report on those different timeframes?

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors