Hey gang, can I get some support? We are trying t...
# gooddata-cloud
t
Hey gang, can I get some support? We are trying to report on "count of completions" by "tag name" The LDM has completion <- content -> taggings <- tag name, hopefully foreign key direction is clear from that. We have a metric 'count of completions' defined as
SELECT COUNT({label/completions.id})
We are able to report on f.ex content.content_type by tag name, but not on the metric (or anything to do with completions). What are we doing wrong?
we have f.ex teams <-> team users <-> users -> completions and can do count of completions, view by team name
which seems similar
ok, so I tried adding a connection going from taggins to content, making it M:N content <-> taggings. This allows the reporting to work, however it is not logically correct - a tagging can refer to only one content. Is this going to sting us?
(content <-> tags would be correct, so that may be why this works, but it's via that taggings join table)
m
Hi Thomas, the M:N definition may lead indeed to troubles down the road, specifically in the way Analytical Desginer aggregates facts and attributes, you may see duplicated results. Not to say, the computation may take longer and it could cause unnecessary stress on the data warehouse. You may need to redefine your metric so it works in the correct context, for example, by adding the USING keyword:
SELECT COUNT({label/inventory.productid}) USING {label/purchases.purchaseid}
. There are more details as to how to properly work with COUNT in the documentation here: https://www.gooddata.com/docs/cloud/create-metrics/maql/aggregation/count/ Lastly, please take into account the direction of the arrows, as it determines which dataset’s data can be analyzed (sliced) by the data from the other dataset. Please take a look at the following documentation which goes over some tips for data modelling: https://university.gooddata.com/tutorials/data-modeling/logical-data-model-five-pro-tips-for-data-modelling/
t
does the direction of the arrows NOT need to reflect the direction of the 1:n?
no, that cannot be. If I try to reverse the direction I simply cannot - the FK is in taggings, not in content
I'm a bit unconvinced that using is relevant here, what reason do we have to believe that ambiguity is the problem? There's nothing wrong with the count of completions, it is straightforwardly a count of records
hi, can I get some more support here?
m
Hi Thomas, can you please provide a direct link to the metric? I will take a closer look and will report back with my findings
t
how would you like things set up? M:N, 1:N?
you probably also want to look at the LDM here right
the metric is not a problem, it's just a simple count
note that in its current state, things appear to work as expected. The M:N is logically incorrect tho as stated upthread.
m
Thanks for the links
Could you change the connection back to 1:N, ie. how it was originally set?
t
done
m
The issue arises because there is no direct reference to the "Tags" dataset in the "Completions" dataset. A simple way to verify this is by adding the "Id" attribute from the "Completions" dataset to an insight and then attempting to break it down by the "Tag name" attribute from the "Tags" dataset. You’ll notice that the "Tag name" attribute will not even be available, as it does not directly relate to the attribute already added. From our logs, the count metric fails with the error
Multiple contexts for count, attribute='attribute/completions.id/df566d0354e04365b659c67b12c34766'
when not using a M:N connection, as the analytic engine cannot determine where the attribute "Tag name" is located. While context errors can often be resolved by introducing the
USING
keyword in the metric definition, you are correct that this would not work here, as the root cause lies in how the datasets are connected. With this said, the issue should be resolved by reviewing and adjusting the dataset connections.
t
reviewing and adjusting them to...
@Moises Morales?
m
Hey @Thomas, I see no changes in the LDM. Do you need a hand with anything?
t
yeah
the issue should be resolved by reviewing and adjusting the dataset connections.
adjusting them to what? What is your recommendation in this case?
M:N?
m
I would say connecting the datasets directly, but unfortunately I am not familiar with your business use case, this will ultimately be up to you to decide
We can help you check what's wrong and why is wrong, but implementation cases fall under our Services Team. If you would be interested in getting in touch with them, I'll be glad to contact them on your behalf.
t
why does this not work, but f.ex completions by team name does?
what's different?
@Moises Morales
m
As pointed out previously, the issue here is with the connection between the dataset. I am afraid I would not be able to advise further, but if you run into any more issues, let us know.
t
but the connection is set up identically (can you at least confirm??) to one that DOES work just fine - completions by team name. Your explanation of "why it's wrong", which you said is within your remit, is either wrong or incomplete in light of this
m
Hi Thomas, let me try to help here. First let me try to clarify how M:N, arrows in model and foreign keys work together in GoodData: Each arrow between datasets in the model is defined by the primary and foreign key and has this “initial” direction (pointing from primary to foreign key). These “normal” 1:N arrows are treated by the engine in a way that metrics can be sliced against their direction, not the other way. The “M:N” or the “double-sided” arrow is technically just a “normal” 1:N arrow with additional property telling the system that it can also allow slicing in the opposite direction. By using a M:N arrow, you are basically telling the system to treat the dataset to which the arrow points to as a bridge table that is actually handling the M:N relationship between attributes. So
content --> taggings
(with foreign key in taggings) means that each tagging has exactly one content; and each content can have zero or more taggings. And
content <-->> taggings
(still with foreign key in taggings) means exactly the same thing, plus it allows to slice content by tags (with the double-sided arrow it is still slicing against the arrow). (I am using
->>
here to mark the “initial” direction based on the foreign key; in the UI it is the black tip of the arrow vs the other being white). Now to your questions If I understand you correctly, you have elsewhere in the model :
f.ex teams <-> team users <-> users -> completions
and you are able to slice
completions
by
team name
That is expected and it is because in this model you can go from
completions
to
f.ex teams
against the direction of those arrows. But In case of
completion <- content -> taggings <- tag name
you can not get from tag to the completion against the direction of the arrow. Some arrows go in different direction and there is no path "against the arrow" from completion to tag. How to fix that I assume from the name that
taggings
is truely a M:N bridge table between content and tag name and therefore it makes sense to have the M:N there. You can set it on both arrows going to the taggings. So changing it to
completion <- content <-->> taggings <<--> tag name
should do the trick. Now you should be able to slice metrics from completion by tags, because it will be against the direction of the arrow - there is now a path from completion all the way to tag name going against the direction of the arrow. I was able to do this in a very simplified model matching yours and am able to slice COUNT(completion ID) metric by tag name - see the screenshots: I hope this helps.
❤️ 1
g
Hi @Thomas did Michal's post help?
t
Yes, a great deal! Thank you so much @Michal Hauzírek
👍 2
m
Happy to help. If you feel that some part of the answer is difficult to understand from the documentation or even completely missing there, please let us know so we can improve it.