Target model is invalid: A data set must have either a fact or an anchor with a label or a valid grain?

  • 10 September 2020
  • 3 replies

  • Anonymous
  • 0 replies

Hi, I’m running into a problem when trying to creating a simple data model. I have two entities named Comment and Tags and a mapping table with foreign keys comment_id and tag_id pointing to both tables.

When I try to publish the data model, I’m getting an error message that says:

“Target model is invalid, a dataset must have either a fact or an anchor with a label or a valid grain.”


Can you tell me what am I doing wrong? Also, what is fact, anchor, label, and grain?



Best answer by Pavel 10 September 2020, 06:52

View original

3 replies

Userlevel 2

Hi Frank,

first, I’m sorry for the unclear message, I have escalated that to my colleagues in the GoodData product team.

Long story short, is basically tells you that you should define a compound primary key on your mapping table. Let me show how to do that:

  1. First, I have created a simple data model similar to what you have described:

Note the gray key icons in the mapping tables. It means they are foreign keys but there is no primary key on that table.

  1. Hover your mouse over the Mapping table, click the More button in the top right, and select “Set Primary Key”:


  2. On the next screen, select both Tag and Comment ID fields and click the “Set key” button:


  3. That’s it, your model is ready to be published. Note the key icons in the Mapping table have turned orange. It means they both belong to the compound primary key. 

I hope this solves your problem but let me briefly explain the terminology and the logic behind the error message.

  • Fact - a numeric column, something you want to aggregate using functions such as SUM, AVG etc
  • “Anchor with a label” or a connection point is basically the same thing as a single column primary key. 
  • Grain - the level of detail in a fact table. In this context, it is basically the same thing is a unique constraint on table (typically containing multiple keys)

We have found out that no useful solution includes a table without a fact or a unique constraint and if it happens, it is usually a mistake or it leads to undesired consequences. In your situation, imagine how you could perform an incremental update of your mapping table without that compound primary key. This is why we require users to specify one of those on each table before a model is published.

Thank you! Just to make sure I got it right:

  • I created my mapping table with comment_id and tag columns but without any constraints.
  • GoodData didn’t let me to do that because it knew that’s not what I wanted (I agree, adding a unique constraint makes a perfect sense here).

Is my understanding correct?

Userlevel 2

@Frank M: yes, that is exactly how it works.